vendredi 20 février 2015

Add Rows together with the same date in SQLite

Im trying to add up values that have the same day of the week


My Query:



SELECT c.CounterID,
total(CASE WHEN strftime('%w', c.Date) = 1 THEN c.Value ELSE 0 END) AS Monday,
total(CASE WHEN strftime('%w', c.Date) = 2 THEN c.Value ELSE 0 END) AS Tuesday,
total(CASE WHEN strftime('%w', c.Date) = 3 THEN c.Value ELSE 0 END) AS Wednesday,
total(CASE WHEN strftime('%w', c.Date) = 4 THEN c.Value ELSE 0 END) AS Thursday,
total(CASE WHEN strftime('%w', c.Date) = 5 THEN c.Value ELSE 0 END) AS Friday,
total(CASE WHEN strftime('%w', c.Date) = 6 THEN c.Value ELSE 0 END) AS Saturday,
total(CASE WHEN strftime('%w', c.Date) = 0 THEN c.Value ELSE 0 END) AS Sunday
FROM CounterItems c
GROUP BY c.CounterID


Above returns 0 for each Day of the week column. Why isn't it adding up the values?


EDIT: Below is my Table structure



ID|CounterID|Value|Date

Aucun commentaire:

Enregistrer un commentaire