将三个SELECT语句组合在一起

时间:2013-04-05 11:21:35

标签: sql select join

我需要将这三个SELECT语句连接在一起;可能吗?我需要一张桌子作为结果。

/*Soutezni zapasy*/
SELECT
    Jmeno,
    COUNT(CASE WHEN Ucast = 'TRUE' then 1 end) as Pocet_zapasu,
    SUM(CASE WHEN Branky>0 then Branky end) as branek
FROM 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 
WHERE (Kategorie.IDkategorie = 1) AND Zapas_Datum >= '1/1/2013' AND Zapas_Datum < '9/1/2014' AND(Zapas.Druh=1)
GROUP BY Jmeno;

/*Pratelske zapasy*/
SELECT
    Jmeno,
    COUNT(CASE WHEN Ucast = 'TRUE' then 1 end) as Pocet_zapasu,
    SUM(CASE WHEN Branky>0 then Branky end) as branek
FROM 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 
WHERE (Kategorie.IDkategorie = 1) AND Zapas_Datum >= '1/1/2013' AND Zapas_Datum < '9/1/2014' AND(Zapas.Druh=2)
GROUP BY Jmeno;

/*turnaje*/
SELECT
    Jmeno,
    COUNT(CASE WHEN Ucast = 'TRUE' then 1 end) as Pocet_turnaju,
    SUM(CASE WHEN Branky>0 then Branky end) as branek
FROM 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 
WHERE (Kategorie.IDkategorie = 1) AND Turnaj_Datum >= '1/1/2013' AND Turnaj_Datum < '9/1/2014'
GROUP BY Jmeno;

1 个答案:

答案 0 :(得分:1)

尝试UNION声明。

快速信息链接:http://www.w3schools.com/sql/sql_union.asp