Jump to content

Consulta para saber cuanto dinero se han gastado todos los compradores en una determinada categoría/marca


Recommended Posts

SELECT C.firstname, C.lastname, C.email , SUM(OD.total_price_tax_incl) as pvp 
FROM ps_customer C 
INNER JOIN ps_orders O on C.id_customer = O.id_customer
INNER JOIN ps_order_detail OD on O.id_order = OD.id_order
INNER JOIN ps_category_product CP ON CP.id_product = OD.product_id
WHERE CP.id_category = X
GROUP BY C.email
ORDER BY pvp desc

 

En una determinada marca:

SELECT C.email , CAST(SUM(OD.total_price_tax_incl) as decimal(8,2)) as pvp
FROM ps_customer C 
INNER JOIN ps_orders O on C.id_customer = O.id_customer
INNER JOIN ps_order_detail OD on O.id_order = OD.id_order
INNER JOIN ps_product P ON P.id_product = OD.product_id
WHERE P.id_manufacturer = X
GROUP BY C.email
ORDER BY pvp desc

 

Edited by victorweb (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites
  • victorweb changed the title to Consulta para saber cuanto dinero se han gastado todos los compradores en una determinada categoría/marca

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More