I have 2 tables (Product and Order) like this:
Product Table:
id | name |
---|---|
1 | A |
2 | B |
3 | C |
Order Table:
id | user_id | product_id | date | quantity |
---|---|---|---|---|
1 | 1 | 1 | 2022-07-01 | 2 |
2 | 1 | 1 | 2022-07-02 | 3 |
3 | 1 | 2 | 2022-07-01 | 5 |
4 | 1 | 1 | 2022-07-02 | 2 |
5 | 1 | 1 | 2022-07-03 | 12 |
6 | 1 | 3 | 2022-07-05 | 2 |
7 | 1 | 2 | 2022-07-05 | 1 |
expect table
Name | 2022-07-01 | 2022-07-02 | 2022-07-03 | 2022-07-04 | 2022-07-05 |
---|---|---|---|---|---|
A | 2 | 3 | 12 | 0 | 0 |
B | 5 | 0 | 0 | 0 | 1 |
C | 0 | 0 | 0 | 0 | 2 |
How to write a MySQL query to get the result like the 'expect table'