select 'line'=sum(case isonline when 1 then 1 else 0 end), 'offline'=sum(case isonline when 0 then 1 else 0 end)from tb
select sum(case isonline when 1 then 1 else 0 end) as online, sum(case isonline when 0 then 1 else 0 end) as offline from table
DECLARE @TB TABLE(IsOnLine INT) INSERT @TB SELECT 1 UNION ALL SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0SELECT SUM(CASE WHEN IsOnLine=1 THEN 1 ELSE 0 END) AS ONLINE, SUM(CASE WHEN IsOnLine=0 THEN 1 ELSE 0 END) AS OFFLINE FROM @TB /* ONLINE OFFLINE ----------- ----------- 4 5 */
select sum(case IsOnLinewhen 0 then 1 else 0 end) as line,sum(case IsOnLinewhen 1 then 1 else 0 end) as line1 from TableName
select sum( case when int =1 then 1 else 0 end ) line , sum( case when int =0 then 1 else 0 end ) offline from IsOnLine
select line=sum(IsOnLine), offline=sum(case when IsOnLine=0 then 1 else 0 end) from tb
'offline'=sum(case isonline when 0 then 1 else 0 end)from tb
sum(case isonline when 1 then 1 else 0 end) as online,
sum(case isonline when 0 then 1 else 0 end) as offline
from table
INSERT @TB
SELECT 1 UNION ALL
SELECT 0 UNION ALL
SELECT 0 UNION ALL
SELECT 1 UNION ALL
SELECT 1 UNION ALL
SELECT 1 UNION ALL
SELECT 0 UNION ALL
SELECT 0 UNION ALL
SELECT 0SELECT SUM(CASE WHEN IsOnLine=1 THEN 1 ELSE 0 END) AS ONLINE,
SUM(CASE WHEN IsOnLine=0 THEN 1 ELSE 0 END) AS OFFLINE
FROM @TB
/*
ONLINE OFFLINE
----------- -----------
4 5
*/
sum(
case when int =1 then 1
else 0
end
) line ,
sum(
case when int =0 then 1
else 0
end
) offline
from
IsOnLine
select line=sum(IsOnLine),
offline=sum(case when IsOnLine=0 then 1 else 0 end)
from tb