首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-03-11 
能否同时查询两个分组条件--分栏目统计今日更新软件数selectclassid,今日更新count(1)fromarticlewhereda

能否同时查询两个分组条件
--分栏目统计今日更新软件数
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

热点排行