🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: chile.comp.programacion
Article #718

Re: Como hacer consulta sql

#718
From: Luis León Cárdenas Graide
Date: Mon, 17 Dec 2007 15:48
59 lines
2719 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

El Lun 17 Dic 2007 11:25 escuch� un rumor en chile.comp.programacion donde
Chano 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?
> 
> Gracias.


Probaste haciendo un JOIN entre ambas queryes?

- -- 
Luis Le�n C�rdenas Graide - www.linkedin.com/in/luiscardenasgraide
PGP FingerPrint: 437E 48AB 0093 62AC 07DA F016 EBD8 DBD3 2ECE 5829
Linux User #415.072 - http://counter.li.org
liberaciondigital.org: Ciudadanos frente a las pol�ticas tecnol�gicas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHZpo269jb0y7OWCkRAjHBAJ9qXdSnGLdwf9UQ8ppVbz2Y7NLUxQCfQmQy
Y9c0AZPQYeUkeQsnXyPF36g=
=jKKg
-----END PGP SIGNATURE-----
Technical Details
Message-ID: <fk65nn$rti$1@helcaraxe.dcc.uchile.cl>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!news.kjsl.com!news.nivel5.cl!news.cec.uchile.cl!helcaraxe.dcc.uchile.cl!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!news2.google.com!news1.google.com!news.glorb.com!news.kjsl.com!news.nivel5.cl!news.cec.uchile.cl!helcaraxe.dcc.uchile.cl!not-for-mail
From: Luis León Cárdenas Graide <lucho.SIN.ESTO.stein@gmEil.com>
Newsgroups: chile.comp.programacion
Subject: Re: Como hacer consulta sql
Date: Mon, 17 Dec 2007 12:48:01 -0300
Organization: DCC - Universidad de Chile
Lines: 59
Message-ID: <fk65nn$rti$1@helcaraxe.dcc.uchile.cl>
References: <fk60s1$sne$1@localhost.localdomain>
Reply-To: lucho.SIN.ESTO.stein@gmEil.com
NNTP-Posting-Host: anakena.dcc.uchile.cl
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8Bit
X-Trace: helcaraxe.dcc.uchile.cl 1197906487 28594 192.80.24.6 (17 Dec 2007 15:48:07 GMT)
X-Complaints-To: newsmaster@dcc.uchile.cl
NNTP-Posting-Date: Mon, 17 Dec 2007 15:48:07 +0000 (UTC)