Thank you Misa, the without-temp-tables query has worked flawlessly.
On Wed, Jun 13, 2012 at 5:01 PM, Misa Simic <misa.simic@gmail.com> wrote:
> I think you can have all in one query, without temp tables:
>
> SELECT r.rid, r.cards, to_char(r.stamp, 'DD.MM.YYYY
> HH24:MI') as day,
> c.bid, c.trix, c.pos, c.money, c.last_ip, c.quit,
> u.id, u.first_name, u.avatar, u.female, u.city,
> u.vip > CURRENT_DATE as vip
> FROM pref_rounds r, pref_cards c, pref_users u
> WHERE u.id = c.id and
> r.rid = c.rid and
> r.rid in (
>
> select rid
> from pref_cards
> where stamp > now() - interval '1 day' and
> id in (
> select id
> from pref_money
> where yw = to_char(current_timestamp - interval '1
> week', 'IYYY-IW')
> order by money
> desc limit 10
>
> ) and
> bid = 'Misere' and
> trix > 0
>
>
> )
> order by rid, pos;