Alexander, W.: Query mit Join auf gleiche Tabelle

Beitrag lesen

Hallo Bernhard,

Ergänzung:

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,  
(SELECT COUNT(*) FROM __test ts WHERE HOUR(ts.`created`) = HOUR(t.`created`)) AS actions  
  
FROM __test t  
GROUP BY HOUR(created)  
ORDER BY HOUR(created) ASC

Vorausgesetzt type ist niemals NULL.

Die Tabelle heißt im Beispiel "__test".

Gruß Alexander.