|
版本: |
|
小版本号: |
|
|
|
数据库: |
|
服务器操作系统: |
|
应用服务器: |
|
客户端操作系统: |
|
浏览器: |
|
|
|
我要把2个表的数据合并起来,看论坛的帖子,使用下面的代码,但是提示我的ksql语句错误,我找不出来错误地点。
public static Table queryMZ_MZYPGL1(String concept,String select,String from,String aggregate,String dataModel,String fnModel,String condition,List range,Boolean distinct,String idColumn,String filter,Integer limit,Integer offset,String columns,String orderBy,String aggregateColumns,Map variables){
//将UI传过来的过滤条件放入ksql
String where = "";
if(filter != null && !"".equals(filter)){
where = " and " + filter;
}
//String sql = " from ER_WPXX ER_WPXX " + where;
//计算出总记录数
int cnt = 0;
Table tCount = KSQL.select("select count(a.MD5) as cnt from (select M_mzddgl.fKHMC as fKHMC,M_ddfypc.D3 as D3,M_mzddgl.MD5 as MD5,M_ddfypc.D2 as D2,M_ddfypc.D5 as D5,M_ddfypc.D6 as D6,M_ddfypc.D12 as D12,M_ddfypc from M_ddfypc M_ddfypc optional join M_mzddgl M_mzddgl on M_ddfypc.D1 = M_mzddgl where M_ddfypc.D12 > :addDays( :currentDate() , 0 - 30) AND M_mzddgl is not null "+where+" union select '' as fKHMC,'' as D3,MZ_MZYPGL.Y1 as MD5,MZ_MZYPGL.Y5 as D2,1 as D5,2 as D6,MZ_MZYPGL.Y3 as D12,MZ_MZYPGL from MZ_MZYPGL MZ_MZYPGL where MZ_MZYPGL.Y4 <> '原煤仓' and MZ_MZYPGL.Y4 <> '精煤仓' and MZ_MZYPGL.Y3 > :addDays( :currentDate() , 0 - 5)"+where+") a group by a.MD5", variables, dataModel, null);
Iterator<Row> it1 = tCount.iterator();
if(it1.hasNext()){
Row r = it1.next();
cnt = r.getInt("cnt");
}
//加上offset和limit实现分页
Table table = KSQL.select(" select M_mzddgl.fKHMC as fKHMC,M_ddfypc.D3 as D3,M_mzddgl.MD5 as MD5,M_ddfypc.D2 as D2,M_ddfypc.D5 as D5,M_ddfypc.D6 as D6,M_ddfypc.D12 as D12,M_ddfypc from M_ddfypc M_ddfypc optional join M_mzddgl M_mzddgl on M_ddfypc.D1 = M_mzddgl where M_ddfypc.D12 > :addDays( :currentDate() , 0 - 30) AND M_mzddgl is not null "+where+" union select '' as fKHMC,'' as D3,MZ_MZYPGL.Y1 as MD5,MZ_MZYPGL.Y5 as D2,1 as D5,2 as D6,MZ_MZYPGL.Y3 as D12,MZ_MZYPGL from MZ_MZYPGL MZ_MZYPGL where MZ_MZYPGL.Y4 <> '原煤仓' and MZ_MZYPGL.Y4 <> '精煤仓' and MZ_MZYPGL.Y3 > :addDays( :currentDate() , 0 - 5)"+where+" order by D12 desc" + " limit "+Integer.toString(offset)+","+Integer.toString(limit), variables, dataModel, null);
//不需要设置主键
//table.getProperties().put(Table.PROP_NAME_ROWID, "ER_WPXX");
//设置总记录数
table.getProperties().put(Table.PROP_DB_COUNT, cnt);
return table;
}
}
|
|