Create a crosstab report (Oracle)

Source: Internet
Author: User
Tags crosstab
oracle| Create
Create a crosstab report

CREATE TABLE T1 (
Goodid number is not NULL,
Saledate date NOT NULL,
Salesum Number (10)
);

Requirement to generate a product sales statement for each month of the year

M1 m2 m3 ... M12
G1
G2
.
.
.
Gn

The following is the SQL that generates the report

SELECT Goodid,
SUM (Decode (saledate, ' mm '), ' To_char ', salesum)) "01",
SUM (Decode (saledate, ' mm '), ' To_char ', salesum)) "02",
SUM (To_char (saledate, ' mm '), ' decode ', salesum)) "03",
SUM (Decode (saledate, ' mm '), ' To_char ', salesum)) "04",
SUM (Decode (saledate, ' mm '), ' To_char ', salesum)) "05",
SUM (Decode (saledate, ' mm '), ' To_char ', salesum)) "06",
SUM (Decode (To_char (saledate, ' mm '), ' modified ', salesum)) "07",
SUM (Decode (saledate, ' mm '), ' To_char ', salesum)) "08",
SUM (Decode (saledate, ' mm '), ' To_char ', salesum)) "09",
SUM (Decode (To_char (saledate, ' mm '), ' ten ', Salesum)) "10",
SUM (Decode (To_char (saledate, ' mm '), ' one ', salesum)) "11",
SUM (Decode (saledate, ' mm '), ' To_char ', salesum) "12"
from T1
where To_char (saledate, ' yyyy ') = ' 2004 '
GROUP BY Goodid
Order BY Goodid;




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.