Calculate the best-selling product by category

0

Having these 4 tables:

TB_CAT_PRODUCTO (id_cat,nom_cat)
TB_PRODUCTO (id_pro,nom_pro,id_cant)
TB_PEDIDO (id_ped,fecha_ped
DETALLE_PEDIDO (id_ped,id_pro,cantidad,importe)

How would you find the best-selling product by category in a time interval?

    
asked by Hara8kuda 04.07.2018 в 07:21
source

1 answer

0

Look at this example:

For a table with cat, prod, quantity you can do it like this:

select max(suma),cat from 
  (select sum(cantidad) as suma, cat, pro from tabla group by cat,pro) as x

In your case you must build the internal select by joins between your tables.

    
answered by 04.07.2018 в 12:05