Created
September 8, 2017 11:31
-
-
Save fabiosussetto/b767727e5fb7b2badccd5987f422138a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"tot": 1, | |
"date": "2017-09-08", | |
"category_id": 3, | |
"name": "Uniform Issues" | |
}, | |
{ | |
"tot": 1, | |
"date": "2017-09-06", | |
"category_id": 3, | |
"name": "Uniform Issues" | |
}, | |
{ | |
"tot": 2, | |
"date": "2017-09-08", | |
"category_id": 2, | |
"name": "HR Issues" | |
} | |
SELECT g.category_name, json_agg(g) as dates FROM | |
( | |
SELECT count(*) AS tot, i.created_at::date AS date, ic.id AS category_id, ic.name AS category_name | |
FROM {Issue} i | |
INNER JOIN {IssueCategory} ic ON ic.id = i.issue_category_id | |
GROUP BY i.issue_category_id, ic.name, ic.id, i.created_at::date | |
) g | |
GROUP BY g.category_name | |
{ | |
"category_name": "Uniform Issues", | |
"dates": [ | |
{ | |
"tot": 1, | |
"date": "2017-09-08", | |
"category_id": 3, | |
"category_name": "Uniform Issues" | |
}, | |
{ | |
"tot": 1, | |
"date": "2017-09-06", | |
"category_id": 3, | |
"category_name": "Uniform Issues" | |
} | |
] | |
}, | |
{ | |
"category_name": "HR Issues", | |
"dates": [ | |
{ | |
"tot": 2, | |
"date": "2017-09-08", | |
"category_id": 2, | |
"category_name": "HR Issues" | |
} | |
] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment