Tengo que hacer un query que muestre el valor de una variable y el resultado de 5 contadores. Lo de los contadores ya lo solucioné (gracias a este foro), pero la "variable" sale 3 veces en la misma tabla por lo tanto se repite 3 veces lo mismo en el resultado, el resultado del query en postgres es este:
Código:
Y lo que quiero que salga es esto:Variable | COUNT1 | COUNT2 | COUNT3 | COUNT4 | COUNT5 4 | 1 | 1 | 1 | 1 | 1 4 | 1 | 1 | 1 | 1 | 1 4 | 1 | 1 | 1 | 1 | 1
Código:
(Una sola vez)Variable | COUNT1 | COUNT2 | COUNT3 | COUNT4 | COUNT5 4 | 1 | 1 | 1 | 1 | 1
El query es este:
Código sql:
Ver original
SELECT c1.variable, c2.count1, c3.count2, c4.count3, c5.count4, c6.count5 FROM (SELECT t1.dato AS variable FROM tabla1 AS t1 WHERE t1.llave = 4) AS c1, (SELECT COUNT(t2.dato) AS count1 FROM tabla2 AS t2 WHERE t2.llave = 4) AS c2, (SELECT COUNT(t3.dato) AS count2 FROM tabla3 AS t3 WHERE t3.llave = 4) AS c3, (SELECT COUNT(t4.dato) AS count3 FROM tabla4 AS t4 WHERE t4.llave = 4) AS c4, (SELECT COUNT(t5.dato) AS count4 FROM tabla5 AS t5 WHERE t5.llave = 4) AS c5, (SELECT COUNT(t6.dato) AS count5 FROM tabla6 AS t6 WHERE t6.llave = 4) AS c6;
Pregunta: Cómo limito a que la "variable" salga una sola vez, es decir, que muestre el valor "4" una sola vez?
Gracias