Integer cnt = Integer.valueOf(payInfoDao.getCurrentSession().createSQLQuery("select count(*) from (select t.mechno,count(*) from (select * from boc_payinfo " + whereStr + ") t, mp_merinfo m where t.mechno = m.mechno group by t.mechno) as b ").list().get(0).toString());
你试试这样吧。
StringBuffer sb = new StringBuffer();
sb.append("select count(*) from (select t.mechno,count(*) from (select * from boc_payinfo");
sb.append(whereStr);
sb.append(") t, mp_merinfo m where t.mechno = m.mechno group by t.mechno) as b ");
String res = payInfoDao.getCurrentSession().createSQLQuery(sb.toString()).list().get(0).toString();
Integer cnt = Integer.valueOf(res);
这是你的SQL语句,明显你压根就没别名,或者说对于别名,你理解错了。
select count(*) from //这是最外层,你查出来的只是一个数字,总过多少条记录
(
//这里则是查询t表和m表的双表连接查询
select t.mechno,count(*) from
(
//根据你的SQL语句,这里你是想将在boc_payinfo表查到的东西,用t表示这些查询内容
select * from boc_payinfo " where条件 "
) t, mp_merinfo m
where t.mechno = m.mechno
group by t.mechno
) as b//你这里的as b,放这里表示的是将t表和m表连接查询内容重新组合成一个表,用b表示。
别名放表名后面是表示对表加别名,只有在你查询的列明属性后面加别名,才是为列属性加别名。
你这语句,最后输出的结果只是count(*),计算查询到的总记录条数,跟别名什么,一点毛关系都没有
在你的查询语句别名前面加上AS试试看
SELECT count (*)
FROM (SELECT t.mechno
, count ( *)
FROM (SELECT *
FROM boc_payinfo " + whereStr + ") AS t
, mp_merinfo AS m
WHERE t.mechno = m.mechno
GROUP BY t.mechno) AS b