只需要把訂單簽收時間擷取為年,where條件判斷為今年,在把訂單簽收時間擷取為月根據月分組,sum(訂單**),這樣子就可以查詢出一年中每個月的訂單金額
和查詢年訂單差不多,擷取簽收時間為月周,在根據簽收時間擷取為周天,分組就可以了
查詢結果-- omsumamountactuallypaid為訂單金額
-- omreceivingdate為簽收時間
-- ordermaster 為訂單表
-- date_format(omreceivingdate,'%m') 將時間轉化為月
--year(omreceivingdate) 將時間轉化為年
select
sum(omsumamountactuallypaid)
,date_format(omreceivingdate,
'%m'
)as m from ordermaster o
year
(omreceivingdate)
=year
(curdate())
group
by m
查詢結果-- yearweek(date,1)中國的周
-- yearweek(date)外國星期天就算下一周了
select
sum(omsumamountactuallypaid)
as money, date_format(omreceivingdate,
'%w'
)as id from ordermaster o yearweek(date_format(omreceivingdate,
'%y-%m-%d'),
1)= yearweek(curdate(),
1)group
by id;
其他也都差不多,思路都一樣,轉換日期,分組
mysql 按年 月 周 日分組查詢
以下列資料庫表中的資料為例來說明按年 月 周 日的分組查詢 按年查詢 select date format t.time,y month time,sum t.quantity total from time demo t group by month time 結果為 按月查詢 select da...
001 MySQL報表查詢
1.簡單的demo語句進行報表統計 2.基於簡單的demo語句進行公升級 1.sql語句 set foreign key checks 0 table structure for test drop table if exists test create table test fid int 10 ...
MySQL支援按年月日查詢
在業務環境中,總是想要篩選出不同時間條件下的資料,例如我只想查詢當天資料,當月資料或者本年資料。於是就想通過mysql自帶的幾個時間函式進行簡單的實現。select from cars location where year create time year now and month create...