Mysql-Query monthly summary amount

select extract(year_month from dy.order_date),sum(dy.sale_amount) from table_name dy group by extract(year_month from dy.order_date)

The result is as follows:

Insert picture description here


The EXTRACT()function is used to return a single part of the date/time, such as year, month, day, hour, minute, and so on.

##语法
EXTRACT(unit FROM date)

1. unitForyear_month

select distinct extract(year_month from dy.order_date) from table_name dy 
Insert picture description here


2. unitforyear

select distinct extract(year from dy.order_date) from table_name dy 
Insert picture description here

3. unitFormonth

select distinct extract(month from dy.order_date) from table_name dy 
Insert picture description here

4. unitforday

select distinct extract(day from dy.order_date) from table_name dy 
Insert picture description here


5. unitforweek

#查询当日所处周数
select distinct extract(week from dy.order_date) from table_name dy 
Insert picture description here


unitThe remaining parameter values ​​are as follows

Insert picture description here