Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/03/2013, 13:44
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 9 meses
Puntos: 774
Respuesta: Group by pero ordenar por fecha

Código SQL:
Ver original
  1. SELECT * FROM(
  2. SELECT * FROM (
  3. SELECT id_material,ubicacion, ISNULL(SUM(cantidad),0) AS total FROM recepcion WHERE id_material = {$id_material} ORDER BY fecha ASC GROUP BY id_material,ubicacion) t1
  4. LEFT JOIN (SELECT MAX(fecha) max_fecha,ubicacion FROM recepcion GROUP BY recepcion) AS t2 ON (t1.ubicacion=t2.ubicacion)
  5. ) t3 ORDER BY max_fecha ASC
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me