隐式、显式

确定最佳顾客的另一种方式(二)

https://www.nowcoder.com/practice/b5766f970ae64ac7944f37f5b47107aa


select
    c.cust_name,sum(oi.quantity * oi.item_price) total_price -- 查询的字段
from Orders o,OrderItems oi,Customers c -- 三张表并成一张
where o.order_num = oi.order_num and o.cust_id = c.cust_id -- 连接的基础条件
group by c.cust_name -- 以顾客名字进行分组
having total_price >= 1000 -- 消费金额不低于$1000
order by total_price;

-- 显式
select
    c.cust_name,sum(oi.quantity * oi.item_price) total_price
from Orders s
-- 连接条件
join OrderItems oi using(order_num)
join Customers c using(cust_id)
group by c.cust_name
having total_price >= 1000
order by 2;

全部评论

相关推荐

Wy_m:只要不是能叫的上名的公司 去实习没有任何意义 不如好好沉淀自己
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务