Ver Mensaje Individual
  #23 (permalink)  
Antiguo 09/05/2010, 11:45
Avatar de mortiprogramador
mortiprogramador
Colaborador
 
Fecha de Ingreso: septiembre-2009
Ubicación: mortuoria
Mensajes: 3.805
Antigüedad: 14 años, 7 meses
Puntos: 214
Respuesta: Unir tablas en un renglon

Hola

Bueno, teniendo en cuenta la consulta más reciente
del post y modificandola quedaría así

Código MySQL:
Ver original
  1.   DISTINCT(C.codcliente) `Cod. Cliene`, C.nombre `Nombre`,
  2.   IFNULL(SUM(R.importetotal), 0)  `Importe RES`,
  3.   SUM(CAST(REPLACE(R.peso, ' kg','') AS UNSIGNED)) `Peso .RES`,
  4.   COUNT(R.peso) `Ventas ACHURA`,
  5.   IFNULL(SUM(A.importeventaachura), 0) `Importe Total ACHURA`,
  6.   IFNULL(SUM(CAST(REPLACE(R.peso, ' kg','') AS UNSIGNED)), 0) `Peso ACHURA`,
  7.   COUNT(R.peso) `Ventas RES`,
  8.   SUM(CAST(REPLACE(R.peso, ' kg','') AS UNSIGNED)) + IFNULL(SUM(CAST(REPLACE(R.peso, ' kg','') AS UNSIGNED)), 0) `Total Peso`,
  9.   IFNULL(SUM(R.importetotal), 0)  + IFNULL(SUM(A.importeventaachura), 0) `Total valor`
  10. FROM clientes C
  11.   LEFT JOIN res R ON C.codcliente = R.codcliente
  12.   LEFT JOIN achuras A ON C.codcliente = A.codcliente AND R.fecha_salida = A.fecha_salida
  13. GROUP BY C.codcliente;

Dando este resultado

Código MySQL:
Ver original
  1. +-------------+----------+-------------+-----------+---------------+----------------------+-------------+------------+------------+-------------+
  2. | Cod. Cliene | Nombre   | Importe RES | Peso .RES | Ventas ACHURA | Importe Total ACHURA | Peso ACHURA | Ventas RES | Total Peso | Total valor |
  3. +-------------+----------+-------------+-----------+---------------+----------------------+-------------+------------+------------+-------------+
  4. |           1 | julian   |    17043.02 |      1365 |            17 |               717.40 |        1365 |         17 |       2730 |    17760.42 |
  5. |           2 | isaura   |     5334.49 |       446 |             5 |                 0.00 |         446 |          5 |        892 |     5334.49 |
  6. |           3 | santiago |     4126.78 |       332 |             3 |                 0.00 |         332 |          3 |        664 |     4126.78 |
  7. |           4 | madre    |     4577.40 |       373 |             4 |                 0.00 |         373 |          4 |        746 |     4577.40 |
  8. |           5 | david    |     3820.99 |       314 |             3 |                 0.00 |         314 |          3 |        628 |     3820.99 |
  9. +-------------+----------+-------------+-----------+---------------+----------------------+-------------+------------+------------+-------------+

Es así??
Y si no es así, entonces por favor has un bosquejo de como debería salir
y que fechas usar para que se de el resultado que quieres
Ahora, ten en cuenta que estas queriendo traer datos indistintamente si
tienen o no ventas, cuando lo lógico sería querer traer datos si hay ventas
pues como yo lo entiendo es una consulta para saber las ventas o no?
Bueno, analizalo y nos comentas
saludos