Tema: Order By
Ver Mensaje Individual
  #6 (permalink)  
Antiguo 17/08/2012, 10:37
jurena
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Cáceres
Mensajes: 3.735
Antigüedad: 16 años, 1 mes
Puntos: 300
Respuesta: Order By

perdona, había un error:
ORDER BY CAST( SUBSTRING( serie, 4 ) AS UNSIGNED ) , no_factura

pero si agrupas también por fecha, deberías ordenar igualmente por fecha... ¿no?


select date_format(fecha,'%Y/%m/%d'), serie, no_factura, nombre_cliente, nombre_planta,
(sum(CL05)*5 + sum(CL10)*10 + sum(CL20)*20 + sum(CL25)*25 + sum(CL35)*35 + sum(CL40)*40 + sum(CL60)*60 + sum(CL100)*100) as libras,
sum(equival_galones) as cilindros,sum(carburacion) as carburacion, sum(granel) as granel,
(contado + credito) as total


from tmp c

where
date_format(fecha, '%Y/%m/%d') between pFechaInicial and pFechaFinal
and upper(codigo) = upper(pCodigoPlanta)
group by serie,no_factura,fecha
ORDER BY CAST( SUBSTRING( serie, 4 ) AS UNSIGNED ) , no_factura, fecha