读书人

能否同时查询两个分组条件解决办法

发布时间: 2012-03-11 18:15:39 作者: rapoo

能否同时查询两个分组条件
--分栏目统计今日更新软件数
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 今日更新
209186
210331
21118
21410
215118
21748
218269
21927
220190
我还想增加一列叫做 [软件总数],就是那个分类的软件总数,我不知道怎么写,既能按当日这个条件汇总出今日更新,又能不要这个条件汇总数软件总数
classid 今日更新 [软件总数]
209186
210331
21118
21410
215118
21748
218269
21927
220190

[解决办法]
加子查下

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

读书人网 >SQL Server

热点推荐