当前位置:网站首页>MySQL counts the total sales data of each month
MySQL counts the total sales data of each month
2022-07-24 08:17:00 【Rice noodles er】
MySQL Count the total sales data of each month
In a ‘temp’ There is a sales table in the database (bb_sale), The structure is as follows
| Field name | type | explain | remarks |
|---|---|---|---|
| F1 | Varchar | sales ID | |
| F2 | Varchar | Sales date | Date format :2014-02-14 |
| F3 | Varchar | Sales amount |
The data in the table are as follows
(1) Statistics 2014 year 1 to 12 month , Total sales data of each month , The format is as follows : month 、 amount of money
SELECT b. month ,COALESCE(SUM(a.F3),0) AS amount of money
FROM bb_sale a RIGHT JOIN
(
SELECT '2014-01' AS month FROM dual
union
SELECT '2014-02' AS month FROM dual
union
SELECT '2014-03' AS month FROM dual
union
SELECT '2014-04' AS month FROM dual
union
SELECT '2014-05' AS month FROM dual
union
SELECT '2014-06' AS month FROM dual
union
SELECT '2014-07' AS month FROM dual
union
SELECT '2014-08' AS month FROM dual
union
SELECT '2014-09' AS month FROM dual
union
SELECT '2014-10' AS month FROM dual
union
SELECT '2014-11' AS month FROM dual
union
SELECT '2014-12' AS month FROM dual
) b
ON LEFT(a.F2,7)=b. month
GROUP BY b. month
Running effect :
(2) Statistics 2014 year 1 In the 12 Total sales data of the month , The format is as follows : month 、 amount of money . The months here are a little different , such as 1 Data for the month , Refer to 1 month 15 No. to 2 month 15 Data between numbers , Empathy 2 Data for the month , Refer to 2 month 15 No. to 3 month 15 Data between numbers , And so on .
SELECT '2014-01' AS month ,COALESCE((SELECT SUM(F3) FROM bb_sale WHERE F2>='2014-01-15' AND F2 <'2014-02-15'),0) AS amount of money
UNION
SELECT '2014-02' AS month ,COALESCE((SELECT SUM(F3) FROM bb_sale WHERE F2>='2014-02-15' AND F2 <'2014-03-15'),0) AS amount of money
UNION
SELECT '2014-03' AS month ,COALESCE((SELECT SUM(F3) FROM bb_sale WHERE F2>='2014-03-15' AND F2 <'2014-04-15'),0) AS amount of money
UNION
SELECT '2014-04' AS month ,COALESCE((SELECT SUM(F3) FROM bb_sale WHERE F2>='2014-04-15' AND F2 <'2014-05-15'),0) AS amount of money
UNION
SELECT '2014-05' AS month ,COALESCE((SELECT SUM(F3) FROM bb_sale WHERE F2>='2014-05-15' AND F2 <'2014-06-15'),0) AS amount of money
UNION
SELECT '2014-06' AS month ,COALESCE((SELECT SUM(F3) FROM bb_sale WHERE F2>='2014-06-15' AND F2 <'2014-07-15'),0) AS amount of money
UNION
SELECT '2014-07' AS month ,COALESCE((SELECT SUM(F3) FROM bb_sale WHERE F2>='2014-07-15' AND F2 <'2014-08-15'),0) AS amount of money
UNION
SELECT '2014-08' AS month ,COALESCE((SELECT SUM(F3) FROM bb_sale WHERE F2>='2014-08-15' AND F2 <'2014-09-15'),0) AS amount of money
UNION
SELECT '2014-09' AS month ,COALESCE((SELECT SUM(F3) FROM bb_sale WHERE F2>='2014-09-15' AND F2 <'2014-09-15'),0) AS amount of money
UNION
SELECT '2014-10' AS month ,COALESCE((SELECT SUM(F3) FROM bb_sale WHERE F2>='2014-10-15' AND F2 <'2014-11-15'),0) AS amount of money
UNION
SELECT '2014-11' AS month ,COALESCE((SELECT SUM(F3) FROM bb_sale WHERE F2>='2014-11-15' AND F2 <'2014-12-15'),0) AS amount of money
UNION
SELECT '2014-12' AS month ,COALESCE((SELECT SUM(F3) FROM bb_sale WHERE F2>='2014-12-15' AND F2 <='2014-12-31' or F2>='2014-01-01' AND F2<'2014-01-15'),0) AS amount of money
Running effect :
边栏推荐
- 【线性代数】深入理解矩阵乘法、对称矩阵、正定矩阵
- P1739 expression bracket matching problem solution
- EZDML reverse engineering import database analysis practical operation tutorial
- 我在微软的这六个月
- Generative model and discriminant model
- Natural language processing hanlp
- Kotlin coroutine (II): scope and cancellation
- 33-SparkSql的介绍、DataFrame和DataSet
- jmeter中JSON提取器使用
- FPGA integrated project - image edge detection system
猜你喜欢
![[wechat applet development] (II) wechat native bottom tabbar configuration](/img/74/5f5da7ea47f95a25011ba52959f480.png)
[wechat applet development] (II) wechat native bottom tabbar configuration
![[shutter] the shutter doctor reports an error](/img/09/20279b3ed71a18b28566ddbe212597.png)
[shutter] the shutter doctor reports an error
![[Google play access] payment server token acquisition](/img/c6/d095ea2b88a11bf6b4bdd80499932c.png)
[Google play access] payment server token acquisition

Robot operation continuous learning thesis (1) original text reading and Translation -- primitive generation strategy learning without catastrophic forgetting in robot operation

Vidar-Team战队专访:AS WE DO, AS YOU KNOW.

DGL库中一些函数或者方法的介绍

Android kotlin uses a coroutine instead of a callback function (suspendcoroutine usage)

Wechat payment V3 version of openresty implementation and pit avoidance Guide (service side)

The vision group of Hegong University Sky team trained day3 - machine learning, strengthened the use of Yolo models, and learned pumpkin books and watermelon books

Markdown basic grammar learning
随机推荐
Hegong sky team vision training day4 - traditional vision, contour recognition
Figure New Earth: how the RVT format BIM model modeled by Revit can accurately match the map with texture
P1305 new binary tree solution
Default risk early warning preliminary competition scheme of bond issuing enterprises [AI competition]
A knight's journey
(dkby) DFL learning notes
[database] complete SQL statement
Robert operator, Sobel operator, Laplace operator
[matlab] (IV) application of MATLAB in linear algebra
Zhouzhihua machine learning watermelon book chapter 2 model evaluation and selection - accuracy and model generalization evaluation method, self-help method and integrated learning
Learning dynamic Siamese network for visual object tracking full text translation
Private traffic + apps, new opportunities for e-commerce drainage
Figure New Earth: how to import CAD files with modified elevation datum (ellipsoid)
[Beijiao] image processing: basic concepts, image enhancement, morphological processing, image segmentation
Intelligent robots and intelligent systems (Professor Zhengzheng of Dalian University of Technology) -- 3. Industrial robots
Go: how to gracefully time out
图的认识与存储
*Code understanding * common function parsing in pytoch
*Project recurrence * project implementation of thesis based on contextbasedemotionrecognitionusingematicdataset
Shared lock, exclusive lock, mutex lock, pessimistic lock, optimistic lock, row lock, table lock, page lock, non repeatable read, lost modification, read dirty data