For the past 2 days I've been struggling with writing this query to export data from firebird. Here's the structure of the data:
WHENINVOICED SALESTAX REMOTELOCATIONID
04.02.2011, 17:45:41.171 2.22 4
04.02.2011, 17:50:06.359 1.53 4
04.02.2011, 17:53:57.093 3.33 4
04.02.2011, 17:54:42.156 0.52 4
04.02.2011, 17:55:15.406 0.59 4
04.02.2011, 17:52:43.618 1.57 9
04.02.2011, 17:54:12.977 3.57 9
04.02.2011, 17:55:28.930 16.49 5
04.02.2011, 17:58:59.977 11.09 5
04.02.2011, 17:59:10.696 5.83 5
04.02.2011, 16:57:53.281 1.15 6
04.02.2011, 16:59:56.296 2.58 6
04.02.2011, 17:03:03.484 1.75 6
04.02.2011, 17:12:23.890 3.23 6
04.02.2011, 17:14:57.859 0.76 6
04.02.2011, 17:16:11.484 8.90 6
04.02.2011, 17:17:31.781 0.76 6
What I want to achieve, is a sum of all SALESTAX figures multiplied by 7.66666666 for each hour.
The code I have so far is:
SELECT sum(salestax * 7.66666666) AS COUNTER FROM INVOICE WHERE wheninvoiced> Current_timeStamp- 1 GROUP BY (EXTRACT(HOUR FROM WHENINVOICED))
This produces:
127.2667
9.506667
44.62
74.82667
177.6367
405.1067
327.1367
121.2867
63.48
This works absolutely perfectly, except this only pulls data for hours where there is data to sum. I instead need it to generate a row for each 24 hours in the day, and place zero's against the hours for which there is no data.
Ideas?