当前位置:网站首页>力扣1082,1084题解_sql查询类型的题目
力扣1082,1084题解_sql查询类型的题目
2022-06-10 19:28:00 【踏过山河,踏过海】
解题思路
as取别名
join on表连接
group by分组
having 条件
代码
1084.销售分析III
# Write your MySQL query statement below
/*编写一个SQL查询,报告2019年春季才售出的产品。即仅在2019-01-01至2019-03-31(含)之间出售的商品。 以 任意顺序 返回结果表*/
select s.product_id,p.product_name
from sales as s
join product as p
on s.product_id=p.product_id/*将两个表连接起来*/
group by s.product_id
having min(s.sale_date) >= '2019-01-01' and
max(s.sale_date) <= '2019-03-31'
解题思路
要找出最好的seller,如果有水平相当的,那就需要将他们全部找出来.
将表中对应的seller每行的price相加即为销售额=>将seller_id进行group by分组再求和.
在得到每个seller总销售额以后,按照降序排列,用limit 1取第一名=>这将带来一个问题:如果有平手,则无法取出,解决方法是:先用一个子查询得到最好的seller的销售额,然后再查询销售额等于这个seller即可.
- 销售分析 I
select seller_id
from sales
group by seller_id
having sum(price)=(select sum(price) as pr
from sales
group by seller_id
order by pr desc
limit 1)
边栏推荐
- ESP8266 系统环境搭建
- How to add independent hotspots in VR panoramic works?
- How to stack double and float in the bottom layer of C language
- ResourceNotFoundException : Unable to find resource
- C pointer (interview classic topic exercise)
- How to realize face verification quickly and accurately?
- [observation] shengteng Zhixing: scene driven, innovation first, press the "acceleration key" for Intelligent Transportation
- FS4100 锂电充电管理IC输入12V给8.4V充电IC
- flink啥时候可以支持在sql-client模式下,往yarn上提交任务可以指定applicati
- 终于有人说清楚了Cookie、Session、Token的区别。详解,面试题。
猜你喜欢

C language floating point number storage form

传音 Infinix 新机现身谷歌产品库,TECNO CAMON 19 预装 Android 13

移动端渲染原理浅析

LLDP协议编写要点

Zabbix_ Principle Architecture - installation and deployment - Custom monitoring

How to add independent hotspots in VR panoramic works?

在阿里云国际上使用 OSS 和 CDN 部署静态网站

京东发布基于张量网络加速的大规模、分布式量子机器学习平台TeD-Q

安全隐患?意义有限?挡不住真煮迷你厨具火爆618

Integrate machine learning to make Chrome browser more "understand" you
随机推荐
4.35V锂电充电IC
Is it safe to open an account online for futures? How to open an account specifically
【技术碎片】重名文件 加后缀重命名过滤实现
Is it safe to open a futures account online? How to avoid being cheated?
[FAQ] summary of common problems and solutions during the use of rest API interface of sports health service
Bit operation topic
Mongodb unique index
江波龙 FORESEE XP2000 PCIe 4.0 SSD 多重加密功能,锁定数据安全
How to realize face verification quickly and accurately?
网上开期货账户安全吗?如何避免被骗?
Fs4100 lithium battery charging management IC input 12V to 8.4v charging IC
国家先进计算产业创新(宜昌)中心正式落地 中科曙光、升哲科技联合运营
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE tha
Tidb - quick start, cluster setup
Standing at such a time node today, we may have a clearer understanding of the industrial Internet
Qualcomm qc2.0 fast charging intelligent identification IC fp6719
手写代码 bind
nodejs: 官方文档3 dgram Stream
Rotated Sorted Array旋转排序数组相关题
批量检测不同url的指定端口(py脚本)