sql - multiple query same table but in different columns mysql -
i'm trying more columns summarizing result 2 different tables
set @start_res = 20150301; set @finish_res= 20150501; set @finish_check= 20150801; set @start_check= 20150301; set @daily_hos= 3; select* ( select count(day_in) arr t_hospital day_in between @start_check , @finish_check , res_date between @start_res , @finish_res , id_daily_hos =@daily_hos group day_in )e, (select count(pat_status) ong1 t_hospital pat_status '%ong%' , day_in between @start_check , @finish_check , res_date between @start_res , @finish_res , id_daily_hos =@daily_hos group day_in ) a, (select count(pat_status) rted t_hospital pat_status '%rtde%'and day_in between @start_check , @finish_check , res_date between @start_res , @finish_res , id_daily_hos =@daily_hos group day_in )b, (select count(pat_status) poli t_hospital pat_status '%pol%'and day_in between @start_check , @finish_check , res_date between @start_res , @finish_res , id_daily_hos =@daily_hos group day_in )c, (select count(pat_status) para t_hospital pat_status '%para%' , day_in between @start_check , @finish_check , res_date between @start_res , @finish_res , id_daily_hos =@daily_hos group day_in )d
and of course not work, first displayed column (arr) works while other ones show wrong output.
where wrong?
this pretty common pattern:
select day_in, count(*) arr, sum(if(pat_status '%ong%', 1, 0)) ong1, sum(if(pat_status '%rtde%', 1, 0)) rted, sum(if(pat_status '%pol%', 1, 0)) pol1, sum(if(pat_status '%para%', 1, 0)) para t_hospital day_in between @start_check , @finish_check , res_date between @start_res , @finish_res , id_daily_hos =@daily_hos group day_in
Comments
Post a Comment