How can I convert this table:-
INV DESCRIPTION AMOUNT
--------------------------
1001 CHARGES 100
1001 FREIGHT 30
1001 INSURANCE 20
1002 CHARGES 215
1002 FREIGHT 32
1002 INSURANCE 25
to this format using SQL:-
INV CHARGES FREIGHT INSURANCE
---------------------------------
1001 100 30 20
1002 215 32 25
Use:
In order to support a dynamic list of descriptions, you'd have to specify which database this is for because the dynamic SQL syntax is different for each one.
PIVOT/UNPIVOT is ANSI syntax, but support is limited:
MySQL doesn't support PIVOT, nor does SQLite. I don't know when/if PostgreSQL or DB2 does...