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
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
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
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)
大家看看是不是最简化的?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
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]
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]
from table
group by guest_to_hotel_status
from table1
group by guest_to_hotel_status