Ver Mensaje Individual
  #3 (permalink)  
Antiguo 18/03/2011, 08:18
quimfv
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 1 mes
Puntos: 574
Respuesta: Help con intervalos de un campo a otro

Complemento si tines un multiplicardor (%) que se tiene que aplicar por tramos al total de ventas la solucion no varia mucho...

Código MySQL:
Ver original
  1. SELECT Ventas.idcomercial,
  2.              Ventas.idProducto,
  3.              Ventas.totalventas,
  4.               Ventas.totalventas * (SELECT ti.comision
  5.                       FROM Intervalos ti  
  6.                              WHERE ti.idProducto=Ventas.idProducto
  7.                                  AND ti.minimo<=Ventas.totalventas
  8.                                  AND ti.maximo>=Ventas.totalventas) AS com
  9. FROM TProductos;

Donde

Intervalos
...
idProducto
minimo
maximo
comision
...

1...0......100...0.25 <-- 25%
1...101..200...0.50
2...0......100...0.30
2...101..200...0.60

La comision és un porcentage en tanto por uno.
__________________
Quim
--------------------------------------------------
Ayudar a ayudar es una buena práctica!!! Y da buenos resultados.