i have a group by query which fetch the data, How much qty a user ordered within a date range which results like that.
select od.item_code, o.user_id, SUM(od.total_qty) as qty_sold from `orders` as `o` inner join `order_details` as `od` on `od`.`order_id` = `o`.`order_id` where ( date(`o`.`order_receive_date`) >= '2022-02-01' and date(`o`.`order_receive_date`) <= '2022-02-09' ) group by `od`.`item_code`, `o`.`user_id`
product_id | user_id | qty_ordered |
---|---|---|
11 | U123 | 5 |
22 | U123 | 1 |
22 | U124 | 9 |
11 | U124 | 0 |
11 | U312 | 1 |
22 | U312 | 1 |
now I want to get this data in following format
product_id | U123 | U124 | U312 |
---|---|---|---|
11 | 5 | 0 | 1 |
22 | 1 | 9 | 1 |
please guide me how can i do this either in php , laravel or directly using MySQL query thanks in advance