James B. Byrne wrote:
On Tue, May 19, 2009 17:02, Andy Colson wrote:
so: select max(name), type from food group by type
works cuz we only get one name (the max name) back for each type.
or: select name, type from food group by type, name
which in our example is kinda pointless, but still, give us the
distinct
items for "type, name".
Thanks. I think I am beginning to see this. So, if there are more
than one type for a given currency code and I do not select and
group by type then the having count(whatever) = 1 means that these
rows are not selected either. Is that correct?
I'm not familiar with your data, and I didn't study your sql very hard.
I'm not sure what this will do:
HAVING
COUNT(fxr.currency_code_quote) = 1
The only time I have ever used HAVING is like:
select name from something group by name having count(*) > 1
to find duplicate name's.
you're group by is on 5 fields, but the count is only on one.... so...
If a count is in the select part (like select count(name) from stuff)
it only counts when name is not null... so maybe that having is saying
count where currency_code_quote is not null and there is only one record
per group... I dunno.
-Andy
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general