一个 表里 有 
IsOnLine 字段是 int类型 的 数据 就是 0 合1 我怎样统计出来 是0的 和1 的 分别有 多少个 
如 统计出 这样的数据
  line    offline
   100      80
这样的 

解决方案 »

  1.   

    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
      

  2.   

    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
      

  3.   

    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
    */
      

  4.   

    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
      

  5.   

    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 
      

  6.   


    select line=sum(IsOnLine),
           offline=sum(case when IsOnLine=0 then 1 else 0 end)
    from tb