My Postgres version is 11.15. I have a table like:
id | employee |
---|---|
1 | Anna |
2 | Bill |
3 | Carol |
4 | Dave |
5 | Tom |
The output I need is
id | cumulative_employees |
---|---|
1 | Anna |
2 | Bill, Anna |
3 | Carol, Bill, Anna |
4 | Dave, Carol, Bill, Anna |
5 | Tom, Dave, Carol, Bill, Anna |
I tried using LAG function of PostgreSQL but it only gives me last row value, could not find a way to get all previous rows, number of rows is dynamic and can be anywhere between 12 to 52 rows.
Can you please help me out?