PHP - SQL - 如何在MySQL中创建月度报告?

时间:2021-05-25 15:29:48

I have "Sales" Table in my DB, which contains daily product sales.

我的数据库中有“销售”表,其中包含每日产品销售额。

PHP  -  SQL  - 如何在MySQL中创建月度报告?

1- How to write query that will fetch records first group by date and then group by product & then populate the table.

1-如何编写查询,首先按日期提取记录,然后按产品分组,然后填充表格。

2- Any JQuery plugin to create output like following table.

2-任何JQuery插件,用于创建如下表所示的输出。

Required Output be like this:

必需输出如下:

PHP  -  SQL  - 如何在MySQL中创建月度报告?

3 个解决方案

#1


1  

You can use aggregation function as sum and group by date and product

您可以使用聚合函数作为总和,按日期和产品分组

select date, product, sum(quantity)
from my_table
group by date, product

#2


0  

Try this -

试试这个 -

SELECT date as Date, product as Product, SUM(quantity) as Quantity FROM Sales GROUP BY date, product

#3


0  

Try this:

select cast(date as date) as 'Date', Product, sum(quantity) as 'Quantity'
from sales 
group by cast(date as date), Product
order by  cast(date as date) asc

#1


1  

You can use aggregation function as sum and group by date and product

您可以使用聚合函数作为总和,按日期和产品分组

select date, product, sum(quantity)
from my_table
group by date, product

#2


0  

Try this -

试试这个 -

SELECT date as Date, product as Product, SUM(quantity) as Quantity FROM Sales GROUP BY date, product

#3


0  

Try this:

select cast(date as date) as 'Date', Product, sum(quantity) as 'Quantity'
from sales 
group by cast(date as date), Product
order by  cast(date as date) asc