Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/12/2014, 07:43
gralf
 
Fecha de Ingreso: noviembre-2014
Mensajes: 76
Antigüedad: 9 años, 5 meses
Puntos: 0
no consigo hacer funcionar sum()

con esta consulta

Código MySQL:
Ver original
  1. select id_item, sum('compra'-'taller'-'venta'+'regula_mas'-'regula_menos') as stock from movimiento group by id_item;

obtengo
id_item 1 stock 0
352 stock 0

sobre esta tabla

Código MySQL:
Ver original
  1. id_mov  int(5) unsigned NO  PRI     auto_increment
  2. venta   int(5) unsigned YES        
  3. compra  int(5) unsigned YES        
  4. taller  int(5) unsigned YES        
  5. regula_mas  int(5) unsigned YES        
  6. regula_menos    int(5) unsigned YES        
  7. id_item int(5)  NO  MUL    
  8. id_lente    int(2)  YES MUL    
  9. id_cilindro int(2)  YES MUL    
  10. id_esfera   int(5)  YES MUL

y tengo varios movimientos para esos id_items

Código MySQL:
Ver original
  1. 1       100             2014-12-13 13:37:04 1          
  2. 2       58              2014-12-13 13:37:04 352        
  3. 5   1                   2014-12-13 13:38:48 1          
  4. 6           2           2014-12-13 13:38:48 1          
  5. 7               5       2014-12-13 13:41:25 352        
  6. 8                   2   2014-12-13 13:41:25 1