Permalink: http://gaojingsong.iteye.com/blog/2383799
Preview article: [Complex SQL case -- row and column conversion]
2017
-
07
-
09
Blog Category:
The known source table data is as follows:
PID | on one | Place | |||
Apple | 11 | Beijing warehouse | |||
banana | 22 | Shanghai warehouse | |||
big pear | 44 | Guangzhou warehouse | |||
Apple | 66 | Shenzhen warehouse |
Now it is required to get the inventory report of each commodity, which is convenient for unified scheduling and display
PID | Beijing warehouse | Shanghai warehouse | Guangzhou warehouse | Shenzhen warehouse | …… |
Apple | 11 | 0 | 0 | 66 | |
banana | 0 | 22 | 0 | 0 | |
big pear | 0 | 0 | 44 | 0 |
Fourth solution
Environment preparation: use the Decode function provided by Oracle and DB2