XAE
XAE

Reputation: 646

Postgresql: Looping through a date_trunc generated group

I've got some records on my database that have a 'createdAt' timestamp.

What I'm trying to get out of postgresql is those records grouped by 'createdAt'

So far I've got this query:

SELECT date_trunc('day', "updatedAt") FROM goal GROUP BY 1

Which gives me:

+---+------------+-------------+ | date_trunc | +---+------------+-------------+ | Sep 20 00:00:00 | +---+------------+-------------+

Which are the days where the records got created.

My question is: Is there any way to generate something like:

| Sep 20 00:00:00 | | id | name | gender | state | age | |----|-------------|--------|-------|-----| | 1 | John Kenedy | male | NY | 32 | | | | Sep 24 00:00:00 | | | | id | name | gender | state | age | |----|-------------|--------|-------|-----| | 1 | John Kenedy | male | NY | 32 | | 2 | John De | male | NY | 32 |

That means group by date_trunc and select all the columns of those rows?

Thanks a lot!

Upvotes: 0

Views: 177

Answers (1)

Arihant
Arihant

Reputation: 745

Please try SELECT date_trunc('day', "updatedAt"), name, gender, state, age FROM goal GROUP BY 1,2,3. It will not provide as the structure, you expect, but will "group by date_trunc and select all the columns ".

Upvotes: 1

Related Questions