当前位置:网站首页>力扣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)
边栏推荐
- 企业级存储发展趋势谈:开源存储的冷思考
- 8.4v双节锂电池专业充电ic(FS4062A)
- MySQL backup and manual execution of shell scripts are OK, and crontab scheduled execution fails
- Solution to the problem that JLINK CDC UART driver cannot be installed normally under win7 system
- hidden danger? Limited meaning? Can't stop the real cooking Mini kitchenware hot 618
- Mongodb index unique
- Is it safe to open an account online for futures? How to open an account specifically
- I drew several exquisite charts with plotly, which turned out to be beautiful!!
- One question to explain the past and present life of dynamic planning
- 使用环绕通知对目标方法进行增强—摘抄笔记
猜你喜欢

On the development trend of enterprise storage: cold thoughts on open source storage
![[enter textbook latex record]](/img/f0/5ca60f0894d4ae544e7399d18a3a42.png)
[enter textbook latex record]

How to add independent hotspots in VR panoramic works?

用一个性能提升了666倍的小案例说明在TiDB中正确使用索引的重要性

FPGA state machine

一个10年左右的老程序员说:简单CRUD功能进入无码开发时代1 之 增删改查接口信息

SBC芯片35584数据手册预调节器翻译

【观察】昇腾智行:场景驱动,创新先行,为智慧交通按下“加速键”

After the college entrance examination, VR panoramic tour will show you the beautiful scenery of the scenic spot

国庆期间给大家推荐一个可能会成为2019最佳的CRUD工具
随机推荐
Redis集群形式--哨兵模式集群和高可用模式集群---Redis学习笔记003
[observation] shengteng Zhixing: scene driven, innovation first, press the "acceleration key" for Intelligent Transportation
企业级存储发展趋势谈:开源存储的冷思考
Zabbix_监控ssh/crond服务-微信告警
Mongodb index unique
How to apply VR panorama in home decoration? Experience the real home decoration effect
Is it safe to open a futures account online? How to avoid being cheated?
An old programmer of about 10 years said: simple crud function enters the era of codeless development 1. Adding, deleting, modifying and checking interface information
Redis cluster form - sentry mode cluster and high availability mode cluster - redis learning notes 003
During the college entrance examination this year, all examination sites were in good order, and no sensitive cases affecting safety occurred
When can Flink support the SQL client mode? When can I specify the applicati for submitting tasks to yarn
When the college entrance examination is opened, VR panorama can see the test site in this way
2022 年 DevOps 路线图|Medium
SBC芯片35584数据手册预调节器翻译
Fs2117 boost IC output 5v2.4a synchronous rectification
mysql服务启动失败
I drew several exquisite charts with plotly, which turned out to be beautiful!!
暗黑破坏神不朽数据库怎么用 暗黑破坏神手游不朽数据库使用方法
Recording a super Oolong mental retardation bug may help people like me eat for free
Microsoft Word 教程「5」,如何在 Word 中更改页边距、创建新闻稿栏?