select (select count(*) from 表)总数,count(*) 为1的记录条数 from 表 where cjdm=1

解决方案 »

  1.   

    Select 全部记录条数=t,CJDM为1的记录条数=b from 
       (Select t=Count(*) from 表)tem1,
       (Select b=Count(*) from 表 where CJDM=1)tem2
    --注意,(Select t=Count(*) from 表) 与 tem1之间不能有空格。
      

  2.   

    select (select count(*) from 表)总数,count(*) 为1的记录条数 from 表 where cjdm=1
      

  3.   

    测试数据:
    -------------------------------------
    Select * from 表
    name1 1 1 3
    name1 2 2 3
    name2 2 3 3
    name2 2 4 3
    name3 2 5 3
    name4 1 6 3
    -------------------------------------
    Select 全部记录条数=t,CJDM为1的记录条数=b from 
       (Select t=Count(*) from 表)tem1,
       (Select b=Count(*) from 表 where CJDM=1)tem2全部记录条数      CJDM为1的记录条数 
    -----------       ----------- 
    6                 4
      

  4.   

    select count(*) as totalnum, sum(case when CJDM=1 then 1 else 0 end ) as CJDMnum
    from table 
    select count(*) as totalnum, count(case when CJDM=1 then CJDM else null end ) as CJDMnum
    from table
      

  5.   

    select count(*) as totalnum, sum(case when CJDM=1 then 1 else 0 end ) as CJDMnum
    from table 
    select count(*) as totalnum, count(case when CJDM=1 then CJDM else null end ) as CJDMnum
    from table
      

  6.   

    select count(*) as totalnum, sum(case when CJDM=1 then 1 else 0 end ) as CJDMnum
    from table 
    select count(*) as totalnum, count(case when CJDM=1 then CJDM else null end ) as CJDMnum
    from table
      

  7.   

    select (select count(*) from 表),(select count(*) from 表 where cjdm=1)