您好,我有 2 个表,它们有 2 个这样的列。
DocumentNumber Price
我在表格中显示了相同的 DocumentNumbers,每个文档编号的计数和价格差异。这是我的查询
select DocumentNumber, max(cnt_s) as documentNumber1, max(cnt_s2) as documentNumber1,
max(price_s) - max(price_s2) as PriceDifference
from ((select DocumentNumber, count(*) as cnt_s, 0 as cnt_s2,
sum(price) as price_s, 0 as price_s2
from Sheet s
group by DocumentNumber
) union all
(select DocumentNumber, 0, count(*) as cnt_s2,
0, sum(price) as price_s2
from Sheet2 s2
group by DocumentNumber
)
) t
group by DocumentNumber;
我只想在价格差异之前添加 sheet1 的价格和 sheet2 的价格。建议我一些查询。