select Editor, sum(case passed when 1 then 1 else 0 edn) PassCount,
       sum(1) TotalCount
from article where month(getdate())=month(UpdateTime) 
group by editor order by Editor

解决方案 »

  1.   

    select Editor, sum(case passed when 1 then 1 else 0 edn) PassCount,
           count(*) TotalCount
    from article where month(getdate())=month(UpdateTime) 
    group by editor 
    order by Editor
      

  2.   

    select Editor
    ,被录用的稿件数=sum(case passed when 1 then 1 else 0 end)
    ,投稿总数=count(*)
    from 表
    group by Editor
      

  3.   

    select Editor, sum(passed) PassCount,
           count(*) TotalCount
    from article where month(getdate())=month(UpdateTime) 
    group by editor 
    order by Editor
    你的passed列应该是用0,1表示的吧
      

  4.   


    在ACCESS中应如何去写呢?
    解决就结贴
      

  5.   

    在ACCESS中,运行上述代码,就行了。access 支持上述语句。
      

  6.   

    --ACCESS中就用:select Editor
    ,被录用的稿件数=sum(iif(passed=1,1,0))
    ,投稿总数=count(*)
    from 表
    group by Editor
      

  7.   

    --上面错了,ACCESS中用:select Editor
    ,sum(iif(passed=1,1,0)) as 被录用的稿件数
    ,count(*) as 投稿总数
    from 表
    group by Editor
      

  8.   

    sum(iif(passed=1,1,0)) 最终有两种结果
    sum(1)或是SUM(0),
    SUM 函数是求字段值的和的,
    我还是不太清楚,用在SQL中,sum(case passed when 1 then 1 else 0 edn) 
                 或sum(iif(passed=1,1,0)) as 
     怎么就能求,PASSED 为真的记录个数了呢?
      

  9.   

    to  1ssp(新来的) ( ) access中的与 server2000中的sql有很多不同点,函数语法都有不同按zjcxc(邹建) 的方法,录用数显的全是零,而总数正常
      

  10.   

    passed是什么类型?试试用:select Editor
    ,sum(iif(passed,1,0)) as 被录用的稿件数
    ,count(*) as 投稿总数
    from 表
    group by Editor
      

  11.   

    Editor  //字段名
    站前消防大队
    站前消防大队
    站前消防大队
    站前消防大队
    站前消防大队Passed  //字段名
    Yes
    No
    No
    No
    No
    No
    UpdateTime  //字段名
    2003-12-30 12:01:45
    2003-12-30 11:31:45
    2003-12-30 11:31:25
    2003-12-30 11:30:17
      

  12.   

    我把 zjcxc(邹建) ( ) 改成sum(iif(passed=true,true,false)) as 被录用的稿件数但是显示的是 录用数 -11
           投稿总数 11  记录个数可能跟上面的不贴出来的有所不同,实际的记录要多
      

  13.   

    这样不行吗?select Editor
    ,sum(iif(passed,1,0)) as 被录用的稿件数
    ,count(*) as 投稿总数
    from 表
    group by Editor
      

  14.   

    这样应该可以的:
    select Editor,sum(case when passed=1 then 1 else 0 end) as 录用稿数,sum(1) as 总投稿数 
    from 表
    group by editor
      

  15.   

    我把 zjcxc(邹建) ( ) 改成sum(iif(passed=true,true,false)) as 被录用的稿件数但是显示的是 录用数 -11
           投稿总数 11  记录个数可能跟上面的不贴出来的有所不同,实际的记录要多
    -----------------------------------------------------------------
    true 的数值表示是 -1,false 是 0
    所以才会出现负数
      

  16.   

    如果你是用yes no 来表示是否被录用,则要这样:
    select Editor,sum(case passed when 'yes' then 1 else 0 end) as 录用稿数,sum(1) as 总投稿数 
    from 表
    group by editor
      

  17.   

    --为什么要这样改?
    sum(iif(passed=true,true,false)) as 被录用的稿件数
    --我不是写了几次吗,应该是这样才对啊:
    sum(iif(passed=true,1,0)) as 被录用的稿件数
      

  18.   

    select Editor
    ,sum(iif(passed='YES',1,0)) as 被录用的稿件数
    ,count(*) as 投稿总数
    from 表
    group by Editor
      

  19.   

    sql="select Editor, sum(iif(passed=yes,1,0)) as PassCount,count(*) as TotalCount from article where (ltrim(rtrim(Editor))<>'其它')and(ltrim(rtrim(Editor))<>'admin')and(Passed=true) and(Year(UpdateTime)=year(UpdateTime))and (month(now())=month(UpdateTime)) group by Editor  order  by Editor  desc"上面是我的SQL语句,但是显示的结果却是排名 单位名称   录用数  投稿总数 
    1  站前消防大队  11     11  
    2  西市消防大队  1      1  
      

  20.   

    谢谢各位,我的问题解决了
    马上结贴现在在CSDN中也只有在这个板块中还有能人存在