Thursday, March 5, 2020

Oracle PIVOT

SELECT * FROM DailyIncome
VendorIdIncomeDayIncomeAmount
SPIKEFRI100
SPIKEMON300
FREDSSUN400
SPIKEWED500
SPIKETUE200
JOHNSWED900
SPIKEFRI100
JOHNSMON300
SPIKESUN400
JOHNSFRI300
FREDSTUE500
FREDSTUE200
SPIKEMON900
FREDSFRI900
FREDSMON500
JOHNSSUN600
SPIKEFRI300
SPIKEWED500
SPIKEFRI300
JOHNSTHU800
JOHNSSAT800
SPIKETUE100
SPIKETHU300
FREDSWED500
SPIKESAT100
FREDSSAT500
FREDTHU800
JOHNSTUE600

Query (A)

SELECT * FROM DailyIncome
PIVOT (SUM (IncomeAmount) FOR IncomeDay IN
([MON],[TUE],[WED],[THU],[FRI],[SAT],[SUN])) AS AvgIncome

VendornameMonTueWedThuFriSatSun
AMIT475150475300200100400
PANKAJ360600920800300800600
VINAY500350500800900500400

No comments:

Post a Comment