select count1 , count1/total , 
       count2 , count3/total , 
       count3 , count3/total ,
       count4 , count4/total , 
       count5 , count5/total 
from 
(select count(*)count1 from table where guest_to_hotel_status=1) a ,
(select count(*)count2 from table where guest_to_hotel_status=2) b ,
(select count(*)count3 from table where guest_to_hotel_status=3) c ,
(select count(*)count4 from table where guest_to_hotel_status=4) d ,
(select count(*)count5 from table where guest_to_hotel_status=5) e ,
(select count(*)total from table ) f 

解决方案 »

  1.   

    count(*) 和 count1之间有空格
      

  2.   

    select guest_to_hotel_status,count(*) as qyt ,
    cast(1.0*count(*)/(select count(*) from Utable) as decimal(18,3)) as PerQty 
    from Utable
    group by guest_to_hotel_status
    order by guest_to_hotel_status
      

  3.   

    select guest_to_hotel_status, count(*),
     100*count(*)/
    (select count(*) from table1 where guest_to_hotel_status in (1,2,3,4,5)) 
     from table1 group by guest_to_hotel_status 
    where guest_to_hotel_status in (1,2,3,4,5)
      

  4.   

    我改了其中一些
    大家看看是不是最简化的?select case guest_to_hotel_status
       when '1' then '入住'
       when '2' then '取消'
       when '0' then '确定'
       else '取消'
    end as guest_title,count(*) as qyt ,
    cast(1.0*count(*)/(select count(*) from orderlist) as decimal(18,3)) as PerQty 
    from orderlist
    group by guest_to_hotel_status order by guest_to_hotel_status
      

  5.   

    select
     100*(select count(*) from [table] where guest_to_hotel_status=1)
     /(select count(*) from [table])
    ,100*(select count(*)  from [table]  where guest_to_hotel_status=2)
     /(select count(*) from [table])
    ,100*(select count(*)  from [table] where guest_to_hotel_status=3)
     /(select count(*) from [table])
    ,100*(select count(*)  from [table]  where guest_to_hotel_status=4)
     /(select count(*) from [table])
    ,100*(select count(*)  from [table]  where guest_to_hotel_status=5)
     /(select count(*) from [table])
    from [table]
      

  6.   

    select
     100*(select count(*) from [table] where guest_to_hotel_status=1)
     /(select count(*) from [table])
    ,100*(select count(*)  from [table]  where guest_to_hotel_status=2)
     /(select count(*) from [table])
    ,100*(select count(*)  from [table] where guest_to_hotel_status=3)
     /(select count(*) from [table])
    ,100*(select count(*)  from [table]  where guest_to_hotel_status=4)
     /(select count(*) from [table])
    ,100*(select count(*)  from [table]  where guest_to_hotel_status=5)
     /(select count(*) from [table])--from [table]
      

  7.   

    用行表示,更通用:select guest_to_hotel_status ,100 * count(*)/(select count(*) from [table])
    from table 
    group by guest_to_hotel_status
      

  8.   

    select count(*) / (select count(*) from table1 )
    from table1 
    group by guest_to_hotel_status