日期:2014-05-19  浏览次数:20503 次

能否同时查询两个分组条件
--分栏目统计今日更新软件数
select   classid,今日更新=count(1)   from   article   where   datediff(day,dateandtime,getdate())=1   and   classid   in   (select   classid   from   f_news_getchildclass(208))   group   by   classid

classid   今日更新
209 186
210 331
211 18
214 10
215 118
217 48
218 269
219 27
220 190
我还想增加一列叫做   [软件总数],就是那个分类的软件总数,我不知道怎么写,既能按当日这个条件汇总出今日更新,又能不要这个条件汇总数软件总数
classid   今日更新   [软件总数]
209 186
210 331
211 18
214 10
215 118
217 48
218 269
219 27
220 190

------解决方案--------------------
加個子查詢試下

select
classid,
今日更新=count(1),
软件总数 = (Select Count(*) From article Where classid = A.classid)
from article A
where datediff(day,dateandtime,getdate())=1
and classid in (select classid from f_news_getchildclass(208))
group by classid