Home > Back-end >  SQL great god for help
SQL great god for help

Time:10-15

Beg ace answer! There is now a table containing daily turnover in a year, but monthly group, now calls for a SQ, as follows:

Use of oracle

Table structure:

Company code (key) management code (key) department code customer code date (format: YYYYMMDD) transactions
111 0001 20130101 1000 01 V001
111 0002 20130201 20000 01 V001
111 0003 20130212 2000 01 V001
111 0004 20130201 200000 01 V001
111 0005 20130303 3000 01 V001
111 0006 20130305 5000 01 V001



The extraction results:


in January, February and marchRecord1, 1000, 20000, 3000
Record2 null value 2000 5000
Record3 null null value 200000


Note: same customer is looking for the same department monthly data, but the number of article each month of data may not, also could not, did not use null values...

CodePudding user response:

I am using is Oracle, as follows:

The SELECT management code, department code, customer code, SUBSTR (dates, 5, 2) the MONTH, COUNT (1) the FROM CNT TABLE_ turnover
WHERE SUBSTR (date, 1, 4)='2013'
GROUP BY management code, department code, customer code, SUBSTR (dates, 5, 2);

The SELECT management code, department code, customer code, the MONTH,
NVL (SUM (DECODE (MONTH, '01, CNT, 0)), 0) AS "in January,"
NVL (SUM (DECODE (MONTH, '02, CNT, 0)), 0) AS "in February,"
NVL (SUM (DECODE (MONTH, '03, CNT, 0)), 0) AS "march",
NVL (SUM (DECODE (MONTH, '04, CNT, 0)), 0) AS "April",
NVL (SUM (DECODE (MONTH, '05, CNT, 0)), 0) AS "may",
NVL (SUM (DECODE (MONTH, '06, CNT, 0)), 0) AS "June",
NVL (SUM (DECODE (MONTH, '07, CNT, 0)), 0) AS "July",
NVL (SUM (DECODE (MONTH, '08', CNT, 0)), 0) AS "August",
NVL (SUM (DECODE (MONTH, '09, CNT, 0)), 0) AS "September",
NVL (SUM (DECODE (MONTH, '10', CNT, 0)), 0) AS "October",
NVL (SUM (DECODE (MONTH, '11', CNT, 0)), 0) AS "November",
NVL (SUM (DECODE (MONTH, '12, CNT, 0)), 0) AS "December" FROM (
The SELECT management code, department code, customer code, SUBSTR (dates, 5, 2) the MONTH, COUNT (1) the FROM CNT TABLE_ turnover
WHERE SUBSTR (date, 1, 4)='2013'
GROUP BY management code, department code, customer code, SUBSTR (dates, 5, 2))
GROUP BY management code, department code, customer code, the MONTH

CodePudding user response:

Is actually a transformation problem,

CodePudding user response:

Fluctuate in SQL as well with controls directly
Query to the data set and then set up relevant properties can connect CxPivotGrid data source!

CodePudding user response:

Oracle

Database ah, I haven't even started yet

CodePudding user response:

reference
fluctuate in SQL as well with controls directly
Query to the data set and then set up relevant properties can connect CxPivotGrid data source!

How can you say so,
The great part of SQL performance is to see your SQL statements to write optimization, or poor performance

CodePudding user response:


Other host than the wrong place, should be send in MSSQL

CodePudding user response:

I usually run into this kind of situation, and then create a table, and then insert the data, for example, to create a table, list of 1, 2, 3... In December,
Then use SQL statements the data you need to write, because this is you do into a column, anyway I was such a figure, do not know to have what good method,
  • Related