Alexander, W.: Query mit Join auf gleiche Tabelle

Beitrag lesen

Hallo Bernhard,

SELECT HOUR(created) AS hour,  
    (SELECT COUNT(type) FROM __test ta WHERE ta.type = 'a' AND HOUR(ta.created) = HOUR(t.created)) AS a,  
    (SELECT COUNT(type) FROM __test tb WHERE tb.type = 'b' AND HOUR(tb.created) = HOUR(t.created)) AS b  
FROM __test t  
GROUP BY HOUR(created)  
ORDER BY HOUR(created) ASC

Die Tabelle heißt im Beispiel "__test".

Gruß Alexander.