当前位置:网站首页>LeetCode-1445. Apples and oranges
LeetCode-1445. Apples and oranges
2022-06-12 06:23:00 【Border wanderer】
surface : Sales
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| sale_date | date |
| fruit | enum |
| sold_num | int |
+---------------+---------+
(sale_date,fruit) Is the primary key of the table .
This table contains... In each day " Apple " and " orange " Sales of .
Write a SQL Inquire about , Report every day Apple and orange The difference in the number of sales .
The returned result table , According to the format ('YYYY-MM-DD') Of sale_date Sort .
The query result table is shown in the following example :
Sales surface :
+------------+------------+-------------+
| sale_date | fruit | sold_num |
+------------+------------+-------------+
| 2020-05-01 | apples | 10 |
| 2020-05-01 | oranges | 8 |
| 2020-05-02 | apples | 15 |
| 2020-05-02 | oranges | 15 |
| 2020-05-03 | apples | 20 |
| 2020-05-03 | oranges | 0 |
| 2020-05-04 | apples | 15 |
| 2020-05-04 | oranges | 16 |
+------------+------------+-------------+
Result surface :
+------------+--------------+
| sale_date | diff |
+------------+--------------+
| 2020-05-01 | 2 |
| 2020-05-02 | 0 |
| 2020-05-03 | 20 |
| 2020-05-04 | -1 |
+------------+--------------+
stay 2020-05-01, sold 10 An apple and 8 An orange ( The difference is 10 - 8 = 2).
stay 2020-05-02, sold 15 An apple and 15 An orange ( The difference is 15 - 15 = 0).
stay 2020-05-03, sold 20 An apple and 0 An orange ( The difference is 20 - 0 = 20).
stay 2020-05-04, sold 15 An apple and 16 An orange ( The difference is 15 - 16 = -1).
# Write your MySQL query statement below
SELECT s1.sale_date, (s2.sold_num - s1.sold_num) as diff
FROM Sales as s1 INNER JOIN Sales as s2
ON (s1.fruit != s2.fruit AND s1.sale_date = s2.sale_date)
GROUP BY s1.sale_date边栏推荐
- Textcnn (MR dataset - emotion classification)
- LeetCode-1629. Key with the longest key duration
- Video fire detection based on Gaussian mixture model and multi-color
- PHP 开发环境搭建及数据库增删改查
- Word vector training based on nnlm
- Leetcode-139. Word splitting
- Bulk Rename Utility
- Nodemon cannot load the file c:\users\administrator\appdata\roaming\npm\nodemon PS1, because script execution is prohibited in this system
- CONDA create use virtual environment
- Bert Chinese classification model training + reasoning + deployment
猜你喜欢

Sqlite Cross - compile Dynamic Library

LeetCode-1490. Clone n-ary tree

Introduction to the method of diligently searching for the alliance procedure

Poisson disk sampling for procedural placement

Houdini terrain creation

About why GPU early-z reduces overdraw

Houdini & UE4 programmed generation of mountains and multi vegetation scattering points

leetcode 35. Search insert location

基于报错的 SQL 注入

leetcode 278. First wrong version
随机推荐
Remap function of C different interval mapping
Leetcode-139. Word splitting
QT--实现TCP通信
Bert use
What states do threads have?
Multithreading (V) -- Concurrent tools (II) -- j.u.c concurrent contracting (I) -- AQS and reentrantlock principles
勤于奋寻找联盟程序方法介绍
leetcode 278. First wrong version
Bulk Rename Utility
Introduction to the method of diligently searching for the alliance procedure
(UE4 4.27) customize primitivecomponent
Unity3d display FPS script
Analysis of memory management mechanism of (UE4 4.26) UE4 uobject
姿态估计之2D人体姿态估计 - PifPaf:Composite Fields for Human Pose Estimation
相机图像质量概述
Tips for using the potplayer video player
Leetcode January 12 daily question 334 Increasing ternary subsequence
Houdini script vex learning
[reinstall system] 01 system startup USB flash disk production
Project progress on February 28, 2022