难点:关联字段的选择以及子查询和联结的使用
根据题目,分析解题思路:
在OrderItems表,根据订单号,计算出订单总金额
在Orders表,根据订单号,得出是哪一个顾客
用order_num 列 将 Orders表 与 OrderItems表关联
用cust_id 列 将 Customers 表与 Orders表关联
最后添加订单金额筛选条件和排序
select
a.cust_name,
c.d as total_price
from
Customers a,Orders b
inner join
(
select
order_num,
sum(item_price * quantity) as d
from
OrderItems
group by
order_num
) c on b.order_num = c.order_num
where
a.cust_id = b.cust_id
and c.d >= 1000
order by
total_price

京公网安备 11010502036488号