34,838
社区成员




--author:josy
--editor:galenkeny
select 1 as type,
count(1) as cnt1,
sum(case when type2=3 then 1 else 0 end) as cnt2,
sum(case when type2=4 then 1 else 0 end) as cnt3
from tb
where info='古天乐' and type1=1
union all
select 2 as type,
count(1) as cnt1,
sum(case when type2=3 then 1 else 0 end) as cnt2,
sum(case when type2=4 then 1 else 0 end) as cnt3
from tb
where info='古天乐' and type1=2
declare @q varchar(80) set @q='古天乐'
select type1
, count(1)
, count(case type2 when 3 then 1 end)
, count(case type2 when 4 then 1 end)
from A
where info=@q
group by type1
declare @q varchar(80) set @q='古天乐'
select type1
, count(1)
, count(case type2 when 1 then 1 end)
, count(case type2 when 2 then 1 end)
from A
where info=@q
group by type1
select 1 as type,count(1) as cnt1,sum(case when type2=3 then 1 else 0 end) as cnt2,sum(case when type2=4 then 1 else 0 end) as cnt3 from tb where info='古天乐' and type1=1
union all
select 2,count(1) as cnt1,sum(case when type2=3 then 1 else 0 end) as cnt2,sum(case when type2=4 then 1 else 0 end) as cnt3 from tb where info='古天乐' and type1=2
SELECT COUNT(1) AS [总记录数],
SUM(CASE WHEN type2 = 3 THEN 1 ELSE 0 END) AS [记录数1],
SUM(CASE WHEN type2 = 4 THEN 1 ELSE 0 END) AS [记录数2]
FROM A
WHERE info='古天乐'
AND type1 = 1
UNION
SELECT COUNT(1) AS [总记录数],
SUM(CASE WHEN type2 = 3 THEN 1 ELSE 0 END) AS [记录数1],
SUM(CASE WHEN type2 = 4 THEN 1 ELSE 0 END) AS [记录数2]
FROM A
WHERE info='古天乐'
AND type1 = 2