select count(DI_DeskState) from dbo.PIL_Desk_Info group by DI_City
select count(DI_DeskState) from dbo.PIL_Desk_Info where DI_NetPortState='1' group by DI_City 
请问这2个COUNT的结果怎么放到同一个查询里面?

解决方案 »

  1.   

    [code=SQL]select 
    (select count(DI_DeskState) from dbo.PIL_Desk_Info group by DI_City ) as col1
    ,(select count(DI_DeskState) from dbo.PIL_Desk_Info where DI_NetPortState='1' group by DI_City 
    ) as col2select count(DI_DeskState) as col from dbo.PIL_Desk_Info group by DI_City 
    union all
    select count(DI_DeskState) from dbo.PIL_Desk_Info where DI_NetPortState='1' group by DI_City [/code]
      

  2.   

    select count(DI_DeskState) from dbo.PIL_Desk_Info group by DI_City 
    select count(DI_DeskState) from dbo.PIL_Desk_Info where DI_NetPortState='1' group by DI_City select count(DI_DeskState) ,
           count2=sum(case when DI_NetPortState='1'  then 1 else 0 end)
    from dbo.PIL_Desk_Info group by DI_City 
      

  3.   

    select count1=count(DI_DeskState),count2=sum(case when DI_NetPortState='1' then 1 else 0 end)
    from dbo.PIL_Desk_Info  
    group by DI_City 
      

  4.   

    --竖着
    select count(DI_DeskState) as DI_DeskState from dbo.PIL_Desk_Info group by DI_City
    union all
    select count(DI_DeskState) as DI_DeskState from dbo.PIL_Desk_Info where DI_NetPortState='1' group by DI_City 
      

  5.   

    select 
    (select count(DI_DeskState) from dbo.PIL_Desk_Info group by DI_City ) as col1
    ,(select count(DI_DeskState) from dbo.PIL_Desk_Info where DI_NetPortState='1' group by DI_City ) as col2select count(DI_DeskState) as col from dbo.PIL_Desk_Info group by DI_City 
    union all 
    select count(DI_DeskState) from dbo.PIL_Desk_Info where DI_NetPortState='1' group by DI_City
      

  6.   

    试试:
    select count(DI_DeskState) ,
           count2=sum(case when DI_NetPortState='1'  then 1 else 0 end)
    from dbo.PIL_Desk_Info group by DI_City 
      

  7.   

    --横着
    select 
          count(DI_DeskState) , 
          count2=sum(case when DI_NetPortState='1'  then 1 else 0 end) 
    from 
          dbo.PIL_Desk_Info 
    group by 
          DI_City 
      

  8.   

    select (select count(*) from hh), (select count(*) from hh where id = 1)