--分栏目统计今日更新软件数
select classid,今日更新=count(1) from article where datediff(day,dateandtime,getdate())=1 and classid in (select classid from f_news_getchildclass(208)) group by classidclassid 今日更新
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

解决方案 »

  1.   

    同时看看这个帖。
    http://community.csdn.net/Expert/topic/5366/5366154.xml?temp=.8335382
    搜集另类的sql语句集合
      

  2.   

    加個子查詢試下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
      

  3.   

    這麼改下Select 
    classid,
    今日更新 = SUM(Case When datediff(day,dateandtime,getdate())=1 Then 1 Else 0 End),
    软件总数 = Count(*)
    From article A
    Where classid in (select classid from f_news_getchildclass(208)) 
    Group by classid
      

  4.   

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