🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: chile.comp.programacion
Article #721

Re: Como hacer consulta sql

#721
From: mauricio sthandier r.
Date: Tue, 18 Dec 2007 00:28
50 lines
2190 bytes
SELECT hora, COUNT(*), ISNULL(SUM(CASE resultado WHEN 0 THEN 1 ELSE 0 END),0) FROM #temp
GROUP BY hora

debiera servir en mySQL... aunque hay muchas diferencias de la 3 a la 5

saludos,

"Chano" <chanorecords@gmail.NOSPAM.com> escribi� en el mensaje news:fk60s1$sne$1@localhost.localdomain...
  Teno una tabla con dos campos Hora, Telefono y Resultado

Quiero sacar estadisticas sobre resultados por cada hora.
Para sacar el total de llamadas por hora hago
select hora, count(*) from Tabla group by hora;

y sale algo del estilo

+-----------------+
| Hora | count(*) |
+-----------------+
| 00   |        6 |
| 01   |        2 |
...
+-----------------+

  Si quiero consultar por un resultado especifico

select hora, count(*) from Tabla where Resultado=0 group by hora;

  La duda es: como puedo hacer una consulta que me retorne de una sola vez
ambas consultas en la misma tabla? O sea algo as�:

+-----------------+-------+
| Hora | Total    |Res=0  |
+-----------------+-------+
| 00   |        6 |     3 |
| 01   |        2 |     2 |
...
+-----------------+-------+

  Intent� con union, pero si es que no hay llamadas con Res=0 a alguna
hora, ambas consultas tienen distinta cantidad de columnas.

  Ideas?

Gracias.


-- 
Chano
jgarrido[@]dcc.uchile.cl 
Technical Details
Message-ID: <fk748h$92n$1@aioe.org>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!aioe.org!not-for-mail
References: <fk60s1$sne$1@localhost.localdomain>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,b04a102ed74b68c5
X-Google-Attributes: gid1593cb,public,usenet
X-Google-Language: SPANISH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!aioe.org!not-for-mail
From: "mauricio sthandier r." <quiltro@animalplanet.com>
Newsgroups: chile.comp.programacion
Subject: Re: Como hacer consulta sql
Date: Mon, 17 Dec 2007 21:28:35 -0300
Organization: Aioe.org NNTP Server
Lines: 52
Message-ID: <fk748h$92n$1@aioe.org>
References: <fk60s1$sne$1@localhost.localdomain>
NNTP-Posting-Host: fyX44koKyKmaQ2AETLCIeA.user.aioe.org
X-Complaints-To: abuse@aioe.org
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
X-RFC2646: Format=Flowed; Original
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-Priority: 3
X-MSMail-Priority: Normal