Jump to content

Recommended Posts

Привет!

Помогите, плиз, соорудить sql-запрос, который поможет узнать количество товаров каждого бренда, которые содержатся в тех заказах, что во вкладке "Выполнены".

Link to post
Share on other sites

 

 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 by SeregaDa
Link to post
Share on other sites

 

Для всех заказов (в т.ч. новых, принятых, удаленных). Легко добавите необходимое условие.

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

 

Подсчет совсем негодящий - правильный результат будет давать только в самых простейших случаях...

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...