hqls = "select a.viewUserId,a.byUserId,a.isMyFriend FROM TCounter AS a WHERE a.viewUserId="+ad.getByUserId()+" and a.byUserId<>"+ad.getByUserId()+" and a.isMyFriend=""Y"" GROUP BY a.viewUserId,a.byUserId,a.isMyFriend";
通过,以上的hql 可以得到4条记录, 也是正确的,
问题 是 怎么样,通过 COUNT 统计得到了总记录数
通过
hql = "SELECT COUNT(*) AS num FROM TCounter as bs WHERE bs.viewUserId IN (SELECT a.viewUserId FROM TCounter AS a WHERE a.byUserId="+ad.getByUserId()+" and a.viewUserId>0 and a.viewUserId<>"+ad.getByUserId()+" and a.isMyFriend=""N"" GROUP BY a.viewUserId) and a.isMyFriend=""Y"" GROUP BY a.byUserId) and bs.viewUserId="+ad.getByUserId()+" and bs.byUserId<>"+ad.getByUserId()+" and bs.isMyFriend=""Y""";
上面这个就得到 13条记录[统计到了重复的记录]
怎么样去除重复的~
很无语,这个问题,困惑多时,希望求指导 项目 是 java s2sh 框架
解决方案:5分
LZ数据查出来截个图
解决方案:10分
用distinct可以么?
解决方案:10分
IN (SELECT distinct a.viewUserId FROM
解决方案:5分
你仔细检查下,应该是你写的sql语句有问题
解决方案:10分
LZ重复数据在哪里啊 貌似没找到啊!标注一下啊