Aniket Narvankar

Aniket Narvankar

  • 526
  • 2.1k
  • 607.9k

SQL Query Solution

Jun 13 2024 8:54 AM

Need Help in how to write a sql query to get output as follows
Table

DP SICS_No UY LOB Rate
TR 0003468A 2006 20 30
TR 0003468A 2006 14 27
TR 0003468A 2006 93 17
TR 0003468A 2006 A2 9
TR 0003468A 2006 52 17

Output
DP SICS_NO UY LOB RATE LOB RATE LOB RATE LOB RATE
TR 0003468A 2006 20 30 14 27 93 17 A2 9

Please let me know on how to proceed. I am trying with pivot but it is not working

This was what i was trying


SELECT *
FROM (
    SELECT DP, SICS_No, UY, LOB, Rate
    FROM #temp
) AS source_table
PIVOT (
    MAX(Rate)
    FOR LOB IN ([20], [14], [93], [A2])
) AS pivot_table;


Answers (2)