日期:2014-05-18  浏览次数:21096 次

用了group by分页就没效果了。第二个问题选择列表中的列 'city.shiname' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。
SELECT TOP 17 COUNT(*) as yjs ,danwei ,(COUNT(danwei)*25) as total FROM cpgl 
  WHERE danwei NOT IN(SELECT TOP (17*0) danwei FROM cpgl where adddate in (select adddate from cpgl) and flag = 3 and zhuangtai = 2 group by danwei 
  ORDER BY danwei ASC) AND adddate in (select adddate from cpgl) and flag = 3 and zhuangtai = 2 group by danwei ORDER BY danwei ASC
用了group by分页就没效果了。

SELECT TOP 17 COUNT(*) as yjs ,cpgl.danwei ,(COUNT(danwei)*25) as total, city.shiname FROM cpgl,city 
  WHERE cpgl.flag = 3 and cpgl.zhuangtai = 2 and cpgl.zhuangtai = 2 and cpgl.zone = city.zone group by cpgl.danwei ORDER BY cpgl.danwei ASC

报错了。
选择列表中的列 'city.shiname' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。

------解决方案--------------------
group by 后面字段加上 shiname

select中的字段,除了聚合字段,其他都要在group by中写上
------解决方案--------------------
参考