Re: Trying to find miss and mister of the last month with highest rating
От | Alexander Farber |
---|---|
Тема | Re: Trying to find miss and mister of the last month with highest rating |
Дата | |
Msg-id | CAADeyWgRbP7gzSVLyw5t+kbM-EzW_Tjv04h19_m0W4r2ryawSw@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Trying to find miss and mister of the last month with highest rating (Alexander Farber <alexander.farber@gmail.com>) |
Список | pgsql-general |
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') and u.female=true and r.id=u.id group by r.id , u.first_name, u.avatar, u.city order by count desc limit 1; id | count | first_name | avatar | city ----------------+-------+------------+----------------------------------------------------------- -------------+----------- OK348033534186 | 49 | Елена | http://i398.odnoklassniki.ru/getImage?photoId=194373317258 &photoType=0 | Хабаровск (1 row) (I'm sorry, I'm probably asking same questions again and again and not even not noticing it. SQL is a tough language for me) Should I maybe better use date_trunc( 'month', now() ) - '1 MONTH'::INTERVAL instead of comparing to_char() results? Thank you Alex
В списке pgsql-general по дате отправления: