select count(person) from 表 where 条件1 union all select count(person) from 表 where 条件2
select a.pk,a.cnt,b.cnt from (select pk, count() cnt……from where group by)a, (select pk,count() cnt……from where group by) b where a.pk=b.pk --pk是标记字段,例如你要查人数的范围,比如部门号,班级号之类的
select s.cdtxt,t.streetname,count() from social.grantdetail g inner join sqdta.sqcode s on g.branch1=s.cdcode where s.cdtype='STREET.BRANCHID' and怎么将这两个合进去? select count(person) from 表 where 条件1 union all select count(person) from 表 where 条件2
把where 放宽一点然后用case when 可以吗? select sum(case when 条件1 then 1 else 0) person1,sum(case when 条件2 then 1 else 0) person2 from table where 条件1 or 条件2
select sum(case when 条件1 then 1 else 0 end) person1,sum(case when 条件2 then 1 else 0 end) person2 from table where 条件1 or 条件2
select s.cdtxt,t.streetname,count() from social.grantdetail g inner join sqdta.sqcode s on g.branch1=s.cdcode where s.cdtype='STREET.BRANCHID' and怎么将这两个合进去? select count(person) from 表 where 条件1 union all select count(person) from 表 where 条件2
union all
select count(person) from 表 where 条件2
(select pk, count() cnt……from where group by)a,
(select pk,count() cnt……from where group by) b
where a.pk=b.pk
--pk是标记字段,例如你要查人数的范围,比如部门号,班级号之类的
from social.grantdetail g
inner join sqdta.sqcode s on g.branch1=s.cdcode
where s.cdtype='STREET.BRANCHID' and怎么将这两个合进去?
select count(person) from 表 where 条件1
union all
select count(person) from 表 where 条件2
select sum(case when 条件1 then 1 else 0) person1,sum(case when 条件2 then 1 else 0) person2 from table where 条件1 or 条件2
from social.grantdetail g
inner join sqdta.sqcode s on g.branch1=s.cdcode
where s.cdtype='STREET.BRANCHID' and怎么将这两个合进去?
select count(person) from 表 where 条件1
union all
select count(person) from 表 where 条件2