mysql中的子查询例题_MYSQL子查询例题以及答案

本文通过一系列的子查询例题,详细讲解了如何在MySQL中使用子查询来找出各区域销售代表中销售额最高的,以及针对不同业务场景的数据统计方法,如最大销售额的区域下单数量、购买标准纸张最多的账户详情、消费最多客户的相关活动数据,以及高消费账户和公司平均消费的终身平均金额等。
摘要由CSDN通过智能技术生成

57fdd9678bebb99af21bbac5180aecc3.png

More Subqueries Quizzes

Above is the ERD for the database again - it might come in handy as you tackle the quizzes below. You should write your solution as a subquery or subqueries, not by finding one solution and copying the output. The importance of this is that it allows your query to be dynamic in answering the question - even if the data changes, you still arrive at the right answer.

Provide the name of the sales_rep in each region with the largest amount of total_amt_usd sales.

SELECT * FROM(SELECT rname rname,MAX(totalsum) totalsumFROM(SELECT r.name rname,s.name sname,SUM(total_amt_usd) totalsumFROMaccounts aJOINorders oON o.account_id =a.idJOINsales_reps sON a.sales_rep_id =s.idJOINregion rON r.id =s.region_idGROUP BYr.name,s.nameORDER BY 1,3 desc) su

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值