The following is an address:
Code
Create a cross report
Create TableT1 (
GoodidNumber(10)Not Null,
Saledate dateNot Null,
SalesumNumber(10)
);
Requirement to generate the product sales status table for each month of the annual cost
M 1 m2 M12
G1
G2
.
.
.
GN
The following is the SQL statement used to generate reports.
Select Goodid,
Sum (Decode (to_char (saledate, ' Mm ' ), ' 01 ' , Salesum ))" 01 ",
Sum (Decode (to_char (saledate, ' Mm ' ), ' 02 ' , Salesum ))" 02 ",
Sum (Decode (to_char (saledate, ' Mm ' ), ' 03 ' , Salesum ))" 03 ",
Sum (Decode (to_char (saledate, ' Mm ' ), ' 04 ' , Salesum ))" 04 ",
Sum (Decode (to_char (saledate, ' Mm ' ), ' 05 ' , Salesum ))" 05 ",
Sum (Decode (to_char (saledate, ' Mm ' ), ' 06 ' , Salesum ))" 06 ",
Sum (Decode (to_char (saledate, ' Mm ' ), ' 07 ' , Salesum ))" 07 ",
Sum (Decode (to_char (saledate, ' Mm ' ), ' 08 ' , Salesum ))" 08 ",
Sum (Decode (to_char (saledate, ' Mm ' ), ' 09 ' , Salesum ))" 09 ",
Sum (Decode (to_char (saledate, ' Mm ' ), ' 10 ' , Salesum ))" 10 ",
Sum (Decode (to_char (saledate, ' Mm ' ), ' 11 ' , Salesum ))" 11 ",
Sum (Decode (to_char (saledate, ' Mm ' ), ' 12 ' , Salesum ))" 12 "
From T1
Where To_char (saledate, ' Yyyy ' ) = ' 2004 '
Group By Goodid
Order By Goodid;