我有6个数据表。 我有10个不同的查询,它们产生这样的表
对查询有任何想法吗?我是个初学者,所以有点难。
答案 0 :(得分:1)
听起来您想要union all
和group by
:
with q1 as (
<query1>
),
q2 as (
<query2>
),
. . .
select company, sum(total_percentage)
from ((select q1.* from q1) union all
(select q2.* from q2) union all
. . .
(select q10.* from q10)
) q
group by company;
也就是说,如果对于初始结果需要六个不同的查询,我会感到惊讶。您可能想问另一个问题,是否要简化该问题(但是,请为该问题提供更简单的查询版本)。