我试图添加te数据中的所有内容(dollar_value_us,数量),但不添加运输总额,因为每个交易号都有多个项目,但客户只支付了一次运输。我使用的是以下数据:
https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=01693db7ce05b062804cedeb3b3a7e73
下面是我在实际数据库上使用的查询:
select QUARTER_DATE ,COUNTRY,sum(DOLLAR_VALUE_US), sum(QUANTITY), max(SHIPPING_TOTAL)
from transaction_detail_mv
group by QUARTER_DATE,COUNTRY最终输出的美国应该有运输总金额为35
发布于 2019-05-10 04:43:47
试试这个:
select a.quarter_date, a.country, a.total_shipping, b.total_dollar_value, b.total_quantity
from
(select quarter_date, country, sum(shipping_total) as total_shipping
from
(select distinct quarter_date, country, shipping_total
from transaction_detail_mv)c
group by quarter_date,country
)a
join -- Below is part of your query
(select QUARTER_DATE ,COUNTRY,sum(DOLLAR_VALUE_US) as total_dollar_value, sum(QUANTITY) as total_quantity
from transaction_detail_mv
group by QUARTER_DATE,COUNTRY)b
on a.quarter_date = b.quarter_date
and a.country = b.country测试结果:
https://stackoverflow.com/questions/56067086
复制相似问题