I'm trying to use pivot function in sqlserver to make the transpose happen.
Here is the existed table:
id | account | time |
---|---|---|
123 | abc | 2023/1/2 |
123 | def | 2023/2/1 |
123 | fsd | 2023/2/22 |
456 | ioj | 2023/2/1 |
456 | dju | 2023/2/10 |
Ideally, after the transpose, the output will look like below (only transpose maximum 3 records to the column):
id | account1 | time1 | account2 | time2 | account3 | time3 |
---|---|---|---|---|---|---|
123 | abc | 2023/1/2 | def | 2023/2/1 | fsd | 2023/2/22 |
456 | ioj | 2023/2/1 | dju | 2023/2/10 |
I'm aware that using an inner join can make this happen, but wonder how I can achieve this by using "pivot" in sql server? Thanks.