SeregaDa Posted June 4, 2016 Report Share Posted June 4, 2016 Привет!Помогите, плиз, соорудить sql-запрос, который поможет узнать количество товаров каждого бренда, которые содержатся в тех заказах, что во вкладке "Выполнены". Quote Link to post Share on other sites
SeregaDa Posted June 4, 2016 Author Report Share Posted June 4, 2016 (edited) sql-запрос, который поможет узнать количество товаров каждого бренда, которые содержатся в тех заказах Для всех заказов (в т.ч. новых, принятых, удаленных). Легко добавите необходимое условие. SELECT s_brands.name, count(*) as 'Amount' FROM `s_purchases`, `s_products`, `s_brands`, `s_orders` WHERE s_purchases.product_id = s_products.id AND s_products.brand_id <> 0 AND s_brands.id = s_products.brand_id AND s_purchases.order_id = s_orders.id AND s_orders.paid = 1 GROUP BY s_brands.name ORDER by Amount Edited June 4, 2016 by SeregaDa Quote Link to post Share on other sites
Kors Posted June 5, 2016 Report Share Posted June 5, 2016 Для всех заказов (в т.ч. новых, принятых, удаленных). Легко добавите необходимое условие.SELECT s_brands.name, count(*) as 'Amount' FROM `s_purchases`, `s_products`, `s_brands`, `s_orders` WHERE s_purchases.product_id = s_products.id AND s_products.brand_id <> 0 AND s_brands.id = s_products.brand_id AND s_purchases.order_id = s_orders.id AND s_orders.paid = 1 GROUP BY s_brands.name ORDER by Amount Подсчет совсем негодящий - правильный результат будет давать только в самых простейших случаях... Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.