【发布时间】:2021-09-30 21:35:00
【问题描述】:
我有四个查询,数据取自同一张表。
select sum(unit_sold) as total_unit_sold
from tewt
where order_priority = 'HH'
union all
select avg(unit_sold) as average_unit_sold
from tewt
where order_priority = 'H'
union all
select max(unit_sold) as maximum_unit_sold
from tewt
where order_priority = 'M'
union all
select min(unit_sold) as minimum_unit_sold
from tewt
where order_priority = 'L';
我使用“Union All”来描述所有没有行名和列名的结果。
结果:
total_unit_sold (numeric)
1. 2401
2. 5362.00
3. 7699
4. 6184
但我不知道如何将它们与每个结果的列/行名称一起显示。
任何帮助将不胜感激。
谢谢
【问题讨论】:
-
模拟你想要的输出会有帮助。
标签: sql postgresql join group-by union-all