I have a table in this form (this is just the partial view, the table contains more columns):
| USER | date_of | duration |
|----------|----------------|----------|
| John | 01.08.2017 | 5 |
| Anna | 01.08.2017 | 6 |
| John | 03.08.2017 | 10 |
| Anna | 05.08.2017 | 7 |
| Eugene | 30.08.2017 | 16 |
I need one query (select) that will return the data in the form:
|USER | 01| 02| 03| 04| 05| 06| ... | 29| 30| 31|Total|Count|
|--------|---|---|---|---|---|---|-----|---|---|---|-----|-----|
|Anna | 6| | | | 7| | | | | | 13 | 2 |
|John | 5| | 10| | | | | | | | 15 | 1 |
|Eugene | | | | | | | | | 16| | 16 | 1 |
So, I need to fill timesheet with actual data in columns 01..31 (day of month, 28/29 for February, 31 for August, etc.) with null in empty days, calculate total sum of hrs for each User in column 'Total' and count days with Duration more than 5 into 'Count' column. In the full version, the query will be much more complicated, but for now I need to start with described above.