现在有两个表  一个新闻类别表newstype                              一个新闻表news                     id       typename              id       type      title      content     adddate
 
                      1       娱乐新闻               1     娱乐新闻      XXX        xxx        08.7.10
                      2       体育新闻               2     体育新闻      XXX        XXXX       09.7.20
                    ……       ……                  ……    ……        ……        ……        ……现在要一个统计查询  按加入时间  统计news表中各类别新闻的在一段时间内的总数量的SQL 语句   日期自选  精确到天 显示规则  新闻类别   新闻数量
            

解决方案 »

  1.   

    select type,count(1) as 新闻数量
    from news 
    where ....
    group by type
      

  2.   

    select type as '新闻类别',count(1) as '新闻数量' from news where adddate between 开始日期 and 结束日期 group by type  
      

  3.   

    --显示规则 是什麼
    select 新闻类别,count(*)新闻数量 from newstype,news
    where newstype.新闻类别=news.新闻类别 and news.adddate between @start and @end
      

  4.   


    select type,adddate,count(*) as cou
    from news join newstype on news.type=newstype.typename
    group by type,adddate
    ;
      

  5.   

    --显示规则
    select 新闻类别,count(*)新闻数量 from newstype,news
    where newstype.新闻类别=news.新闻类别 and news.adddate between @start and @end
    group by 新闻类别
      

  6.   


    select type,isnull(count(1),0) as 新闻数量 ,adddate=CONVERT(varchar(10),addate ,120)
    from newstype a left join news b on A.id=B.id
    group by type,CONVERT(varchar(10),addate ,120) 
      

  7.   

    select a.type,isnull(count(1),0) as 新闻数量 ,adddate=CONVERT(varchar(10),addate ,120)
    from newstype a left join news b on A.id=B.id
    group by a.type,CONVERT(varchar(10),addate ,120) 
    修改
      

  8.   

    select type 新闻类别,count(*)新闻数量 
    from news
    where adddate between @start and @end
    group by type ?
      

  9.   

    SELECT 
    TYPENAME AS '显示规则' ,COUNT(*) AS '个数' 
    FROM 
    newstype a 
    left join news b on A.TYPENAME=B.TYPE???
      

  10.   

    SELECT 
    TYPENAME AS '显示规则' ,COUNT(*) AS '个数' 
    FROM 
    newstype a 
    left join news b on A.TYPENAME=B.TYPE
    WHERE ADDDATE BETWEEN TIME1 AND TIME1
    GROUP BY TYPENAME ,CONVERT(VARCHAR(10),ADDDATE,120)
    老忘记分组