简体   繁体   中英

PHP - SQL - How to create a monthly report in MySQL?

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

在此处输入图片说明

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

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

Required Output be like this:

在此处输入图片说明

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

尝试这个 -

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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