Access数据库有一个表T 三个字段id(自增整),IsOk(是/否),class(类型)
我想选择同类型IsOk为真的总数,该类的总数这样子写不行啊
select count(id) as a, count(IsOk=true) as c from T group by class 
要求用group
求救啊!!!!!!!

解决方案 »

  1.   

    select count(id) as a, count(IsOk) as c from T where IsOK='ture' group by class
      

  2.   

    declare @t table(id int IDENTITY(1,1),IsOk varchar(10),class varchar(10))
    insert into @t select 'ture','aaa'
    insert into @t select 'ture','111'
    insert into @t select 'false','222'
    insert into @t select 'ture','333'
    insert into @t select 'false','222'
    insert into @t select 'ture','111'
    insert into @t select 'false','111'
    insert into @t select 'ture','111'select class,count(id) as a, 
           sum(case when IsOk='ture' then 1 else 0 end) as c 
    from @t group by class
      

  3.   

    错误类型没有
    我用的是ASP + Access
      

  4.   

    --------------
    select id_all=count(id),ok_all=cout(IsOk),class from T where IsOk='是' group by class
      

  5.   

    use test
    go
    declare @t table(id int IDENTITY(1,1),IsOk varchar(10),class varchar(10))
    insert into @t select '是','aaa'
    insert into @t select '是','111'
    insert into @t select '否','222'
    insert into @t select '是','333'
    insert into @t select '否','222'
    insert into @t select '是','111'
    insert into @t select '否','111'
    insert into @t select '是','111'
    --------------
    select id_all=count(id),ok_all=count(IsOk),class from @t where IsOk='是' group by class
      

  6.   

    id_all      ok_all      class      
    ----------- ----------- ---------- 
    3           3           111
    1           1           333
    1           1           aaa
      

  7.   

    aniude(重返荣耀) 
    谢谢你的参与 方法不对 
    如果是你的表 我想要的数据结果应该是4 3 111
    2 0 222
    1 1 333
    1 1 a
      

  8.   

    没有深入用过Access。我写的那个在Access里不能执行,提示什么呢?
      

  9.   

    select class,count(id) as a, 
           sum(iif(IsOk=Yes,1,0)) as c 
    from 表 group by class--装了个access试了一下。
      

  10.   

    xeqtr1982(ShaKa) 兄最近在ms sql版很努力 哦
      

  11.   

    select class,count(id) as a, 
           sum(iif(IsOk=Yes,1,0)) as c 
    from 表 group by class
    这个不错
      

  12.   

    select  count(id)
    from T
    group by class
    having by isOK='是'
     你试一下这个,我是初学者.
      

  13.   

    count(id)改为count(id) as a 给这个字段加个名称,
      

  14.   

    哦,不好意思
         having by isOK='true'
      

  15.   

    xeqtr1982(ShaKa) 的应该可以解决问题了
      

  16.   

    这位朋友,试试这条语句看看:
    SELECT COUNT(*) FROM T WHERE IsOK=true AND class="你想检索的类型"给个建议:SQL 检索语句的书写应该规范一下,可以在 SELECT … FROM … WHERE …(ORDER BY…) 语句都用大写,以跟表名、字段名(Microsoft建议首字母大写)区分,这位可以更容易的检查,也方便他人的阅读。另外,最好在调试之前确保你的 SQL 语句是正确的,这个很重要,可以减少你查找错误的时间,你可以在 ACCESS 里的“查询”测试一下 SQL 语句是不是正确的
      

  17.   

    select t.class ,count(id)
    from T t
    where t.IsOk = true
    group by t.class
      

  18.   

    select class,count(id) as a,sum(case when IsOk='true' then 1 else 0 end) as c from T group by class
    这个语句应该没有问题~
      

  19.   

    楼主试了这句了吗?select class,count(id) as a, 
           sum(iif(IsOk=Yes,1,0)) as c 
    from 表 group by class
      

  20.   

    解决了 刚才问题在我
    各位 请注意 case when 不是Access能用的
    iif可以使用~!
    谢谢各位的参与~!