Article View: chile.comp.programacion
Article #720Re: Como hacer consulta sql
From: Ricardo Lemus
Date: Mon, 17 Dec 2007 22:00
Date: Mon, 17 Dec 2007 22:00
45 lines
2390 bytes
2390 bytes
Chano <chanorecords@gmail.nospam.com> dijo: > 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? En postgres, tu amigo es 'LEFT JOIN' -- Ricardo J. Lemus C. [Linux-user: 54183] [rlemus[@]dcc.uchile.cl.NOALSPAM] "Laziness is a very important system administrative virtue" from Essential System Administration, 2nd Ed. by AEllen Frisch, O'Reilly & Associates, p. 342.
Technical Details
Message-ID:
<fk6ric$2a2$1@helcaraxe.dcc.uchile.cl>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!62.111.101.3.MISMATCH!news.germany.com!fu-berlin.de!news.nivel5.cl!news.cec.uchile.cl!helcaraxe.dcc.uchile.cl!not-for-mailReferences:
<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-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!62.111.101.3.MISMATCH!news.germany.com!fu-berlin.de!news.nivel5.cl!news.cec.uchile.cl!helcaraxe.dcc.uchile.cl!not-for-mail
From: Ricardo Lemus <rlemusSACAESTO@SINESTOdcc.uchile.cl>
Newsgroups: chile.comp.programacion
Subject: Re: Como hacer consulta sql
Date: Mon, 17 Dec 2007 22:00:44 +0000 (UTC)
Organization: DCC - Universidad de Chile
Lines: 45
Sender: Ricardo Lemus <rlemus@anakena.dcc.uchile.cl>
Distribution: world
Message-ID: <fk6ric$2a2$1@helcaraxe.dcc.uchile.cl>
References: <fk60s1$sne$1@localhost.localdomain>
NNTP-Posting-Host: anakena.dcc.uchile.cl
X-Trace: helcaraxe.dcc.uchile.cl 1197928844 2370 192.80.24.6 (17 Dec 2007 22:00:44 GMT)
X-Complaints-To: newsmaster@dcc.uchile.cl
NNTP-Posting-Date: Mon, 17 Dec 2007 22:00:44 +0000 (UTC)
User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (Linux/2.6.23-gentoo-r3 (i686))