sql级联

确定最佳顾客的另一种方式(二)_牛客题霸_牛客网

解法一:

select c.cust_name,sum(ot.item_price * ot.quantity) as total_price
from OrderItems ot join Orders o
on ot.order_num = o.order_num join Customers c on o.cust_id = c.cust_id
group by c.cust_name
having total_price >= 1000
order by total_price


解法二;

select c.cust_name,sum(ot.item_price * ot.quantity) as total_price
from OrderItems ot join Orders o,Customers c
where ot.order_num = o.order_num and o.cust_id = c.cust_id
group by c.cust_name
having total_price >= 1000
order by total_price


确定哪些订单购买了 prod_id 为 BR01 的产品(二_牛客题霸_牛客网

解法1:

select cust_id,order_date
from Orders
where order_num in(select order_num
from OrderItems
where prod_id like 'BR01')
order by order_date


解法2:

select cust_id,order_date
from Orders o join OrderItems ot 
on o.order_num = ot.order_num
where prod_id like 'BR01'

猜你喜欢

转载自blog.csdn.net/weixin_56194193/article/details/131480458