【发布时间】:2020-01-29 09:59:09
【问题描述】:
如何将此查询更改为嵌套查询? 下面列出了查询和表。
SELECT
Nation.N_NAME as "nation",
ROUND(
SUM(
Lineitem.L_QUANTITY * (Lineitem.L_EXTENDEDPRICE - Lineitem.L_DISCOUNT)
), 2
) AS "order size"
FROM Nation
JOIN Supplier ON Nation.N_NATIONKEY = Supplier.S_NATIONKEY
JOIN Customer ON Supplier.S_NATIONKEY = Customer.C_NATIONKEY
JOIN Orders ON Customer.C_CUSTKEY = Orders.O_CUSTKEY
JOIN Lineitem ON Orders.O_ORDERKEY = Lineitem.L_ORDERKEY
WHERE Lineitem.L_SUPPKEY = Supplier.S_SUPPKEY
GROUP BY Nation.N_NAME
;
表格如下
国家:N_NATIONKEY,N_NAME
供应商:S_SUPPKEY、S_NAME、S_NATIONKEY
客户:C_CUSTKEY、C_NAME、C_NATIONKEY
订单:O_ORDERKEY、O_CUSTKEY
订单项:L_ORDERKEY、L_SUPPKEY、L_QUANTITY、L_EXTENDEDPRICE、L_DISCOUNT
【问题讨论】: