Re: [SQL] need help in building a query

2008-11-08 Thread Devilâ„¢ Dhuvader
> > > Try: > > bdteste=# SELECT o1.user_id, o1.order_id, '>= 500' AS cond FROM Orders o1 > bdteste-# WHERE (SELECT sum(o2.amount_paid) FROM Orders o2 WHERE > o2.user_id = o1.user_id AND o2.order_id > o1.order_id) < 500 AND > bdteste-#(SELECT sum(o2.amount_paid) FROM Orders o2 WHERE > o2.us

Re: [SQL] need help in building a query

2008-11-08 Thread Devilâ„¢ Dhuvader
yes, I am picking up the specific transaction (order_id) so that I can pickup the create_timestamp and sort it descending. that will list me those users who did transaction more than 500 in the least time. then I can give discount for top 10 users expected output: user_id, create_timestamp(desc) wi