Convert columns to rows in SQL [duplicate]
问题 This question already has answers here : Oracle SQL pivot query (2 answers) Closed last year . I need to write a query which takes rows and converts it into columns - here's my table: Count fname lname id ----------------------------- 1 abc def 20 2 pqr 20 3 abc xyz 20 4 xyz xyz 20 1 abc def 21 1 pqr xyz 22 2 abc abc 22 This is the output I'm trying to produce: id fname lname fname lname fname lname fname lname ------------------------------------------------------------- 20 abc def pqr NULL