Answer the question
In order to leave comments, you need to log in
Add selection by SQL condition?
There is a request like this:
SELECT DATE_FORMAT(`orders`.`date`, '%d.%m.%Y') as `date_sum`, SUM((`orders_items`.`price`)*(`orders_items`.`count`)) AS `money_all`
FROM `orders_items`
LEFT JOIN `orders_groups` ON `orders_items`.`order_group_id` = `orders_groups`.`id`
LEFT JOIN `orders` ON `orders_groups`.`order_id` = `orders`.`id`
LEFT JOIN `goods` ON `goods`.`id` = `orders_items`.`good_id`
LEFT JOIN `orders_status` ON `orders_status`.`id` = `orders_items`.`status_id`
WHERE `orders`.`date` BETWEEN '2016-08-01' AND '2016-08-11'
AND `orders_items`.`status` = 1
AND `orders`.`type` = 1
AND `orders_groups`.`type_id` > 0
AND `orders`.`status` = 1
GROUP BY `date_sum` ORDER BY `orders`.`date` DESC
AND `goods`.`type_id` = 103
----------------------------------------
| date_sum | money_all | money_prod |
----------------------------------------
| 2016-11-08 | 13214141 | 4314123 |
| ... | ... | ... |
Answer the question
In order to leave comments, you need to log in
SELECT DATE_FORMAT(`orders`.`date`, '%d.%m.%Y') as `date_sum`, SUM((`orders_items`.`price`)*(`orders_items`.`count`)) AS `money_all` , `gd`.money_prod AS money_prod
FROM `orders_items`
LEFT JOIN `orders_groups` ON `orders_items`.`order_group_id` = `orders_groups`.`id`
LEFT JOIN `orders` ON `orders_groups`.`order_id` = `orders`.`id`
LEFT JOIN `goods` ON `goods`.`id` = `orders_items`.`good_id`
LEFT JOIN `goods` AS `gd` ON `goods`.`type_id` = 103
LEFT JOIN `orders_status` ON `orders_status`.`id` = `orders_items`.`status_id`
WHERE `orders`.`date` BETWEEN '2016-08-01' AND '2016-08-11'
AND `orders_items`.`status` = 1
AND `orders`.`type` = 1
AND `orders_groups`.`type_id` > 0
AND `orders`.`status` = 1
GROUP BY `date_sum`,`money_prod` ORDER BY `orders`.`date` DESC
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question