Re: [GENERAL] Trying to find miss and mister of the last month with highest rating

2011-07-07 Thread David Johnston
-Original Message- And why can't I add u.name, u.avatar to fetch all the info I need in 1 pass? # select r.id, count(r.id), u.name, u.avatar, u.city from pref_rep r, pref_users u where r.nice=true and to_char(current_timestamp - interval '1 month', 'IYYY-MM') = to_char(r.last_rated, 'IYYY

Re: [GENERAL] Trying to find miss and mister of the last month with highest rating

2011-07-07 Thread Alexander Farber
This seems to work, but I wonder if my query for "the miss of the last month" could be improved # select r.id, count(r.id), u.first_name, u.avatar, u.city from pref_rep r, pref_users u where r.nice=true and to_char(current_timestamp - interval '1 month', 'IYYY-MM') = to_char(r.last_rated, 'IYYY-MM

Re: [GENERAL] Trying to find miss and mister of the last month with highest rating

2011-07-07 Thread Alexander Farber
Do you think this query is good? (or is it allocating loads of strings for the month comparisons?) # select r.id, count(r.id) from pref_rep r, pref_users u where r.nice=true and to_char(current_timestamp - interval '1 month', 'IYYY-MM') = to_char(r.last_rated, 'IYYY-MM') and u.female=true and r.id

Re: [GENERAL] Trying to find miss and mister of the last month with highest rating

2011-07-07 Thread Alexander Farber
Hello, I will do 2 queries - one for female users (to find "the miss of last month) and one for males (the "mister of last month"). Here I can fetch all females rated nicely in June: # select r.id, nice, r.last_rated from pref_rep r, pref_users u where r.nice=true and to_char(current_timestamp -

Re: [GENERAL] Trying to find miss and mister of the last month with highest rating

2011-07-07 Thread David Johnston
-Original Message- From: pgsql-general-ow...@postgresql.org [mailto:pgsql-general-ow...@postgresql.org] On Behalf Of Alexander Farber Sent: Thursday, July 07, 2011 9:54 AM To: pgsql-general Subject: [GENERAL] Trying to find miss and mister of the last month with highest rating # select id,