Re: need nelp with aggregate functions
От | Another Trad |
---|---|
Тема | Re: need nelp with aggregate functions |
Дата | |
Msg-id | af7271950911190816n1e2eddabk357a1815856a7440@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: need nelp with aggregate functions ("Oliveiros C," <oliveiros.cristina@marktest.pt>) |
Список | pgsql-sql |
Thank you all very much.
This "official" forum is really great.
This "official" forum is really great.
2009/11/19 Oliveiros C, <oliveiros.cristina@marktest.pt>
Howdy,It is quite simple, the joins you used would output a long list ofpairs (client,computer), and, as many people has more than one computer, many clients will appear repeated, but the COUNT keyword will count them more than once though.The DISTINCT keyword prevents one client from appearing more than once...It's basically that...Hope this helpedBest,Oliveiros----- Original Message -----From: Another TradTo: Oliveiros C,Sent: Wednesday, November 18, 2009 5:37 PMSubject: Re: [SQL] need nelp with aggregate functionsok, I did: SELECT count(DISTINCT c.cliente_id) as qtd_client,count(cm.cm_id) as qtd_computers
GREAT. It works.
Please, explain me why and how it works, I wanna learn and do by myself next time :)2009/11/18 Oliveiros C, <oliveiros.cristina@marktest.pt>Try substituting the SELECT count(c) as qtd_client,count(cm) as qtd_computersbySELECT count( DISTINCT c.cliente_id) as qtd_client,count(/* put here the primary key of the computer table */ ) as qtd_computersThen tell me if it output what you wantBest,Oliveiros----- Original Message -----From: Another TradSent: Wednesday, November 18, 2009 4:55 PMSubject: [SQL] need nelp with aggregate functionsThe DB structure is in attachment.
I with the number of clients and the number of computers that have processors with "manufacturer" = "INTEL" and "speed" = "2GB"
I am trying:select count(c) as qtd_client, count(cm) as qtd_computersbut is not working
from cliente c
inner JOIN computer cm on (c.cliente_id = cm.cliente_id)
inner join processor p on (cm.processor_id = p.processor_id)
inner join speed s on (s.speed_id = p.speed_id)
INNER JOIN manufacturer m on (p.manufacturer_id=m.manufacturer_id)
where m.manufacturer = 'INTEL'
and s.speed = '2GB'
anyone can help me?
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
В списке pgsql-sql по дате отправления: