StringBuffer sqlExceptSelect = new StringBuffer(); sqlExceptSelect.append(" from " + tbCompany + " a right join " + tbCompanyTop + " b "); sqlExceptSelect.append(" on a.name = b.name "); sqlExceptSelect.append(" where 1=1 "); for (Entry<String, Object> e : record.getColumns().entrySet()) { Object key = e.getKey(); Object value = e.getValue(); if (value == null || value == "") { continue; } sqlExceptSelect.append(" and "); if (key.equals("name")) { sqlExceptSelect.append(" b.name like '%" + value + "%' "); continue; } sqlExceptSelect.append(key).append("=").append('\'').append(value) .append('\''); } if (type.equals("isChina")) { sqlExceptSelect.append(" and ischina = 1"); } else { sqlExceptSelect.append(" and isworld = 1"); }
sqlExceptSelect.append(" order by regist_money desc nulls last ");
sql = sqlExceptSelect.toString(); Page<Record> page = Db .paginate( pageNum, pageSize, "select a.id,b.name,regist_money,money_type,to_Char(open_date,'YYYY-MM-DD') as time,lat,lng ", sql); return page;
数据库使用的pgsql
regist_money 字段存在null 值pgsql 默认降序时候null是在前面的,现在需要null值排在后面所以加了 nulls last
出错问题:
select count(*) from baoji_company a right join baoji_company_top b on a.name = b.name where 1=1 and isworld = 1 nulls last
执行的查询条数sql 会是这样 ,如果不加 nulls last 就好着