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

时间:2018-04-03 03:47:39

标签: javascript php mysql

我想每月和每周显示数据,我已经搜索了很多关于此的内容,但我发现并没有回答我的问题。这是我的表格的样子:

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

2 个答案:

答案 0 :(得分:0)

如果您的列dateposted的类型为timestamp / datetime:

每周报告:

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

月度报告:

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

答案 1 :(得分:0)

每周

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

每月

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