Test table three fields: month, type of data
method one:
select t. "month",
SUM (Case When T. "Type" = 'evaporation' then t. "Data" else 0 end) as "evaporation",
SUM (Case When T. "Type" = "Precipitation 'then t. "data" else 0 end) as "precipitation",
SUM (Case When T. "type" =' temperature 'then t. "data" else 0 end) as "temperature"
from CESHIBIAO T
Group by T ."month"
Method Two :( as above but with different functions)
--decode (train line, change the value of multi-line multi-column display) (the column decode, is the value of a column, that is, the value of a column as a new column columns, MAX aggregate functions can sum, min, avg aggregate and other alternative functions)
select t. "month,"
SUM ( "the DECODE" (T. "Type", 'evaporation', T. "Data", 0)) as "evaporation",
SUM ( "the DECODE" (T. "Type" 'precipitation', T. "data", 0)) as "precipitation",
SUM ( "the DECODE" (T. "type", "temperature", T. "data", 0)) as "temperature"
CESHIBIAO t from
Group by t. "month"
Method three: After the pivot orcale11g
--pivot (train line, change the value of multi-line multi-column display) (for in that column, is the value of a column, that is, the value of a column as a new column column, this column below the value seems to only come from a)
* from SELECT (
SELECT, "month", "data", "type" from ADMIN_CESHIBIAO)
Pivot (
SUM ( "Data") for "type" in ( 'evaporation', 'precipitation', 'temperature')
)
Method four: listagg (no check)
--listagg (combined string is a plurality of rows, to display only one)
Column switch
method one:
select wm_concat("月份") name from ADMIN_CESHIBIAO;
Method two: Replace the comma "|"
select replace(wm_concat("月份"),',','|') name from ADMIN_CESHIBIAO;