0

私は行うのが難しいクエリを持っています =)

Stopsテーブルには次の列があります

Id, Area, SubArea, Date, StopNumber, DownTime

私はこのような結果を得たいと思っています:(私は説明しようとします..)

    Area, SubArea, SUM(StopNumber appened in january) as GEN,
     SUM(StopNumber appened in february) as FEB, etc..
FROM Stops
GROUP BY Area, SubArea

誰でも私を助けることができますか?ありがとうございました :)

4

2 に答える 2

0

これはうまくいくはずです:

SELECT Area, SubArea,
SUM(CASE Month(Date) WHEN 1 THEN 1 ELSE 0 END) AS Jan,
SUM(CASE Month(Date) WHEN 2 THEN 1 ELSE 0 END) AS Feb,
SUM(CASE Month(Date) WHEN 3 THEN 1 ELSE 0 END) AS Mar,
SUM(CASE Month(Date) WHEN 4 THEN 1 ELSE 0 END) AS Apr,
SUM(CASE Month(Date) WHEN 5 THEN 1 ELSE 0 END) AS May,
SUM(CASE Month(Date) WHEN 6 THEN 1 ELSE 0 END) AS Jun,
SUM(CASE Month(Date) WHEN 7 THEN 1 ELSE 0 END) AS Jul,
SUM(CASE Month(Date) WHEN 8 THEN 1 ELSE 0 END) AS Aug,
SUM(CASE Month(Date) WHEN 9 THEN 1 ELSE 0 END) AS Sep,
SUM(CASE Month(Date) WHEN 10 THEN 1 ELSE 0 END) AS Oct,
SUM(CASE Month(Date) WHEN 11 THEN 1 ELSE 0 END) AS Nov,
SUM(CASE Month(Date) WHEN 12 THEN 1 ELSE 0 END) AS [Dec]
FROM Stops
GROUP BY Area, SubArea
于 2013-07-12T08:45:21.290 に答える