I'm trying to output a query that has a count of a group by but also, specifies the list of IDs in that row.
This is what I have so far:
SELECT
title,
period,
COUNT(*)
FROM
table
GROUP BY
title, period
Example database
Title | Period | ID |
---|---|---|
Title2 | MONTH | 321 |
Title1 | DAY | 789 |
Title1 | DAY | 123 |
Title1 | MONTH | 123 |
Output
Title | Period | COUNT(*) |
---|---|---|
Title2 | MONTH | 1 |
Title1 | DAY | 2 |
Title1 | MONTH | 1 |
But I would like the output to be something like:
Title | Period | COUNT(*) | Who? |
---|---|---|---|
Title2 | MONTH | 1 | 321 |
Title1 | DAY | 2 | 123, 789 |
Title1 | MONTH | 1 | 123 |
What do I need to add to my query to get this output? I've tried to use an SELF JOIN
and a SELECT JOIN
, but I cannot quite get the syntax right.