简体   繁体   English

如何在Mysql中生成每月和每周报告?

[英]How to generate Monthly and Weekly report in Mysql?

I want to display the data on a monthly and weekly basis, I already searched lot of stuff about this but what i found doesn't answer my question. 我想每月和每周显示一次数据,我已经搜索了很多关于此的内容,但是发现的内容无法回答我的问题。 Here is what my table looks like: 这是我的桌子的样子:

---------------
+ tblcomplain +
---------------
+ id          +
+ status      +
+ complain    +
+ dateposted  +
---------------

if your column is dateposted is of type timestamp/datetime: 如果您的列已dateposted则为timestamp / datetime类型:

For Weekly Report: 对于每周报告:

select count(*) as totalWeeklycomplaints from tblcomplain group by week(dateposted);

For Monthly Report: 对于月报表:

select count(*) as totalMothlycomplaints from tblcomplain group by month(dateposted);

For weekly basis 每周一次

SELECT 
    *, EXTRACT(WEEK FROM add_date) AS w1
FROM
    product_alert_stock
ORDER BY w1 , add_date ASC

For Monthly basis 每月

SELECT 
    *, EXTRACT(Month FROM add_date) AS m1
FROM
    product_alert_stock
ORDER BY m1 , add_date ASC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM