Ver Mensaje Individual
  #2 (permalink)  
Antiguo 10/09/2009, 11:28
ssh
 
Fecha de Ingreso: agosto-2009
Mensajes: 85
Antigüedad: 15 años, 2 meses
Puntos: 0
Respuesta: Select "variable" + Contador (Count)

Acabo de responderme vía "San Google".

Sólo tengo que agregarle al primer SELECT un "ORDER BY t1.dato LIMIT 1"

Queda así:


Código sql:
Ver original
  1. SELECT  c1.variable, c2.count1, c3.count2, c4.count3, c5.count4, c6.count5 FROM
  2. (SELECT t1.dato AS variable FROM tabla1 AS t1 WHERE t1.llave = 4 ORDER BY t1.dato LIMIT 1) AS c1,
  3. (SELECT COUNT(t2.dato) AS count1 FROM tabla2 AS t2 WHERE t2.llave = 4) AS c2,
  4. (SELECT COUNT(t3.dato) AS count2 FROM tabla3 AS t3 WHERE t3.llave = 4) AS c3,
  5. (SELECT COUNT(t4.dato) AS count3 FROM tabla4 AS t4 WHERE t4.llave = 4) AS c4,
  6. (SELECT COUNT(t5.dato) AS count4 FROM tabla5 AS t5 WHERE t5.llave = 4) AS c5,
  7. (SELECT COUNT(t6.dato) AS count5 FROM tabla6 AS t6 WHERE t6.llave = 4) AS c6;



Y muestra el resultado así:

Código:
Variable | COUNT1 | COUNT2 | COUNT3 | COUNT4 | COUNT5
-------+---------------------------------------------------------------------
      4     |      1      |       1      |      1      |      1      |      1
A lo mejor a alguien le puede servir.
Gracias de todas formas, comparto mi duda y solución con Uds. pues me han ayudado bastante.

Saludos

Última edición por ssh; 10/09/2009 a las 16:02