Home > database >  Oracle conversion issues
Oracle conversion issues

Time:10-11

Branch date sales amount
Jiangsu 20200101 100
Jiangsu 20200102 200
Jiangsu 20200103 300
Jiangsu... .
Jiangsu to yesterday 500
Hebei 20200101 550
Hebei 20200102 765
Hebei 20200103 980
Hebei... .
Hebei to yesterday 800
Hainan 20200101 600
. . .


Branch number, a total of 22, each branch daily sales statistics see above, now to achieve the following result, how to implement?

Branch, 20200101, 20200102, 20200103...
Jiangsu, 100, 200, 300...
Hebei province, 550, 765, 980...
Hainan 600... . .
. . . . .

CodePudding user response:

Select the name,
The sum (decode (dt, '20200101', money)),
The sum (decode (dt, '20200102', money)),
The sum (decode (dt, '20200103', money))
The from the TAB
Group by the name

CodePudding user response:

Days are not fixed well, if it is a fixed number of days, it can be

CodePudding user response:

Dynamic splicing SQL statements

CodePudding user response:

Output the XML format, the pivot can be solved
  • Related