【发布时间】:2021-12-11 16:47:48
【问题描述】:
这是我的示例数据:
这是我的查询:
select * from (
select
typ,
user_name,
sort,
count_pc,
weight
from stat where typ=1 and dat>=trunc(sysdate)
)
pivot
(SUM(to_number(count_pc)) as pc, SUM(to_number(round(weight,0))) as hm
for sort in ('Alcohol','Food','NotFood' ,'Cigarette' ) )
order by user_name asc
TYP USER_NAME 'Alcohol'_PC 'Alcohol'_HM 'Food'_PC 'Food'_HM 'NotFood'_PC 'NotFood'_HM 'Cigarette'_PC 'Cigarette'_HM 1 XX 24 630 24 630 null null null null 1 XY 64 1130 null null null null 38 1130 1 XZ null null null null 128 5130 null null
但我想要一个 sum_pc、sum_weight 在表的和表中(多一行——在本例中为 2)。哪个用户总共有多少台电脑和体重....
期望的输出——黄色:
【问题讨论】:
-
最好知道所需的输出是什么。
-
@RobertoHernandez 已添加。