Select 全部记录条数=t,CJDM为1的记录条数=b from (Select t=Count(*) from 表)tem1, (Select b=Count(*) from 表 where CJDM=1)tem2 --注意,(Select t=Count(*) from 表) 与 tem1之间不能有空格。
select (select count(*) from 表)总数,count(*) 为1的记录条数 from 表 where cjdm=1
测试数据: ------------------------------------- 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
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
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
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
select (select count(*) from 表),(select count(*) from 表 where cjdm=1)
(Select t=Count(*) from 表)tem1,
(Select b=Count(*) from 表 where CJDM=1)tem2
--注意,(Select t=Count(*) from 表) 与 tem1之间不能有空格。
-------------------------------------
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
from table
select count(*) as totalnum, count(case when CJDM=1 then CJDM else null end ) as CJDMnum
from table
from table
select count(*) as totalnum, count(case when CJDM=1 then CJDM else null end ) as CJDMnum
from table
from table
select count(*) as totalnum, count(case when CJDM=1 then CJDM else null end ) as CJDMnum
from table