sql - More Select together -


can me problem? need join these 3 select together...........it possible? need 1 table... collums:jmeno, pocet_zapasu,branek,pocet_zapasu2,branek2,pocet_turnaju,branek3.

/*soutezni zapasy*/ select     jmeno,     count(case when ucast = 'true' 1 end) pocet_zapasu,     sum(case when branky>0 branky end) branek hraci inner join ucast_zapas on ucast_zapas.id_hrace_zapas=hraci.idhrace  inner join zapas on zapas.id_zapas=ucast_zapas.id_zapasu_ucast  inner join kategorie on kategorie.idkategorie=zapas.kategorie_zapas  (kategorie.idkategorie = 1) , zapas_datum >= '1/1/2013' , zapas_datum < '9/1/2014' and(zapas.druh=1) group jmeno;  /*pratelske zapasy*/ select     jmeno,     count(case when ucast = 'true' 1 end) pocet_zapasu2,     sum(case when branky>0 branky end) branek2 hraci inner join ucast_zapas on ucast_zapas.id_hrace_zapas=hraci.idhrace  inner join zapas on zapas.id_zapas=ucast_zapas.id_zapasu_ucast  inner join kategorie on kategorie.idkategorie=zapas.kategorie_zapas  (kategorie.idkategorie = 1) , zapas_datum >= '1/1/2013' , zapas_datum < '9/1/2014' and(zapas.druh=2) group jmeno;  /*turnaje*/ select     jmeno,     count(case when ucast = 'true' 1 end) pocet_turnaju,     sum(case when branky>0 branky end) branek3 hraci inner join ucast_turnaj on ucast_turnaj.id_hrace_turnaj=hraci.idhrace  inner join turnaj on turnaj.id_turnaj=ucast_turnaj.id_turnaje_ucast  inner join kategorie on kategorie.idkategorie=turnaj.kategorie_turnaj  (kategorie.idkategorie = 1) , turnaj_datum >= '1/1/2013' , turnaj_datum < '9/1/2014' group jmeno; 

i think can combine first 2 queries , use add case statements. not sure third, instead of trying combine it, added subquery , used left join it:

select     jmeno,     count(case when ucast = 'true' , zapas.druh=1 1 end) pocet_zapasu,     sum(case when branky> 0and zapas.druh=1 branky end) branek,     count(case when ucast = 'true' , zapas.druh=2 1 end) pocet_zapasu2,     sum(case when branky>0 , zapas.druh=2 branky end) branek2,     pocet_turnaju,     branek3 hraci     inner join ucast_zapas on ucast_zapas.id_hrace_zapas=hraci.idhrace      inner join zapas on zapas.id_zapas=ucast_zapas.id_zapasu_ucast      inner join kategorie on kategorie.idkategorie=zapas.kategorie_zapas      left join (         select             jmeno,             count(case when ucast = 'true' 1 end) pocet_turnaju             sum(case when branky>0 branky end) branek3         hraci             inner join ucast_turnaj on ucast_turnaj.id_hrace_turnaj=hraci.idhrace              inner join turnaj on turnaj.id_turnaj=ucast_turnaj.id_turnaje_ucast              inner join kategorie on kategorie.idkategorie=turnaj.kategorie_turnaj          (kategorie.idkategorie = 1) , turnaj_datum >= '1/1/2013' , turnaj_datum < '9/1/2014'         group jmeno     ) t on hraci.jmeno = t.jmeno (kategorie.idkategorie = 1)      , zapas_datum >= '1/1/2013'      , zapas_datum < '9/1/2014'      , zapas.druh in (1,2) group jmeno; 

without understanding table structure, may able consolidate further. also, wasn't sure table pulling jmeno -- assumed hraci.

from understanding of question, not want use union not create additional columns, additional rows. example select 1 col1 union select 2 return single column 2 rows.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -