on 2024 Apr 23 5:53 AM
I can't solve this "simple" problem, can maybe someone help?
What I have is:
create or replace table mytable (whichamount int, whichdate date) insert into mytable values (100, '2024-01-01'), (200, '2024-01-01'), (300, '2024-02-01'), (400, '2024-03-01'), (500, '2024-04-01'), (600, '2024-04-01');What I want is:
whichdate, whichamount1, whichamount2 '2024-01-01', 100, 200 '2024-02-01', 300, null '2024-03-01', 400, null '2024-04-01', 500, 600
Request clarification before answering.
Here's a similar take with PIVOT:
SELECT * FROM ( SELECT whichdate, whichamount, ROW_NUMBER() OVER (PARTITION BY whichdate ORDER BY whichamount) AS rn FROM mytable ) PivotSourceData PIVOT ( LIST (whichamount) FOR rn IN ( 1 as whichamount1, 2 as whichamount2) ) PivotedData ORDER BY whichdate;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
62 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.