当前位置:网站首页>力扣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)
边栏推荐
- MySQL ---- 常用函数
- Problem with makefile: unable to detect file updates
- 腾讯云数据库TDSQL-大咖论道 | 基础软件的过去、现在、未来
- 历时2年442位作者132个机构!Google发布语言模型评价新基准BIG-bench,204个任务全面评价语言模型能力,附论文
- Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data
- On the development trend of enterprise storage: cold thoughts on open source storage
- 4.35V锂电充电IC
- RT-Thread Smart Win10 64位下编译环境的搭建
- 在阿里云国际上使用 OSS 和 CDN 部署静态网站
- It took 2 years, 442 authors and 132 institutions! Google released the new benchmark big bench for language model evaluation. 204 tasks comprehensively evaluated the language model ability, with paper
猜你喜欢
![[FAQ] summary of common problems and solutions during the use of rest API interface of sports health service](/img/9e/9ce804d84fb8ec9221b7c10bbd6c36.jpg)
[FAQ] summary of common problems and solutions during the use of rest API interface of sports health service

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

KP522201A采用 SOT23-6 封装的 4.5V 至 17V 输入、2A 输出、600kHz 同步降压转换器

测试apk-异常管控netLocation攻击者开发

It took 2 years, 442 authors and 132 institutions! Google released the new benchmark big bench for language model evaluation. 204 tasks comprehensively evaluated the language model ability, with paper

2022 Devops roadmap | medium

今年高考期间各考点秩序井然,未发生影响安全的敏感案事件
![[enter textbook latex record]](/img/f0/5ca60f0894d4ae544e7399d18a3a42.png)
[enter textbook latex record]

One question to explain the past and present life of dynamic planning

Microsoft Word 教程「5」,如何在 Word 中更改頁邊距、創建新聞稿欄?
随机推荐
国庆期间给大家推荐一个可能会成为2019最佳的CRUD工具
C pointer (interview classic topic exercise)
Tutoriel Microsoft Word "5", comment changer les marges de page et créer une barre de nouvelles en word?
FS4060A是4.2V/3A充电IC
Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data
Solving Bob's survival problem by trilogy routine
国家先进计算产业创新(宜昌)中心正式落地 中科曙光、升哲科技联合运营
On the development trend of enterprise storage: cold thoughts on open source storage
8.4v双节锂电池专业充电ic(FS4062A)
FS4100 锂电充电管理IC输入12V给8.4V充电IC
Cloud native community boss blog
腾讯云数据库TDSQL-大咖论道 | 基础软件的过去、现在、未来
nodejs: 官方文档3 dgram Stream
Recording a super Oolong mental retardation bug may help people like me eat for free
Unity 分析内置地形(Terrain)的渲染并做一些有意思的事情
Open the door of the hybrid cloud market, Lenovo xcloud's way to break the situation
Handwritten code bind
测试apk-异常管控netLocation攻击者开发
2022 年 DevOps 路线图|Medium
[observation] shengteng Zhixing: scene driven, innovation first, press the "acceleration key" for Intelligent Transportation