有新闻表(news_content),字段:news_id,news_tile,news_content,news_addtime(datetime,如:2009-03-23 12:12:12 000),news_ediror(编辑)我想查询某编辑在本月每天添加的新闻数量,该怎么写,谢谢各位了。就是这样的结果:news_num           news_addtime      12            2010-03-01      23            2010-03-02      ...                    ...

解决方案 »

  1.   

    select count(1) as news_numm, 
    convert(varchar(10),news_addtime,120) as news_addtime
    from tb 
    group by convert(varchar(10),news_addtime,120)
      

  2.   

    select
     count(1) as news_numm, 
     convert(varchar(10),news_addtime,120) as news_addtime
    from
     tb 
    group by
     convert(varchar(10),news_addtime,120)
      

  3.   

    select count(*) as  news_num ,
    news_addtime
    from news_content
    where datediff(mm,news_addtime ,getdate())=0
    and news_ediror=?
      

  4.   

    谢谢楼上两位,在你们SQL语句的基础上我加了条件(限制在本月)
    结果如下:select count(1) as news_num, 
    convert(varchar(10),news_addtime,120) as news_addtime
    from news_content 
    where  news_ediror='编辑名称' and datediff(month,news_posttime,getdate())=0 
    group by convert(varchar(10),news_addtime,120) 
    order by news_addtime asc