how to sum entries from the last entry to some entry in between dynamically? - Mailing list pgsql-sql

From Devil™ Dhuvader
Subject how to sum entries from the last entry to some entry in between dynamically?
Date
Msg-id aaa67ada0810261122r3d64d346o7b5bb4936624ae0d@mail.gmail.com
Whole thread Raw
List pgsql-sql
<font color="midnightblue" face="Verdana, Arial, Helvetica" size="2"><span class="spnMessageText" id="msg">hi,<br />I
needsome help in creating a sql.<br />the problem is as below.<br /><br />assume that:<br />I am a store keeper <br />
andI have the list of customer(user_id) transactions in my order table.<br />schema: Orders(order_id, user_id,
amount_paid,create_timestamp)<br /><br />I want to give discount of 10% for the customer who made orders of worth (sum)
atleast $500 in the least time from now (i.e last few days, but NOT ALL TIME LEAST TIME TO BUY $500 WORTH GOODS).<br
/>and9% discount for the customer who made $500 in second least time from now.<br />and so on<br /><br
/></span></font><fontcolor="midnightblue" face="Verdana, Arial, Helvetica" size="2"><span class="spnMessageText"
id="msg">thereis no time constraint.<br /> it customer could take any amount of time to make $500.<br />the customer
mightnot even made $500 bill till now in that case I should get the first date.<br /><br />the result can take upto the
firstentry time of the table itself.<br /><br />in short its like sum up entries of each user in order table backwards
(i.efrom last entry to the first) and find the entry that has sum > $500. <br />If there is some user who didnt even
make500 till now in my shop return the first date of transaction/order</span></font>.<br /><br />can anyone help me on
this?<br/> 

pgsql-sql by date:

Previous
From: "Harold A. Giménez Ch."
Date:
Subject: Re: Truncate on pg_dump / pg_restore
Next
From: Bryce Nesbitt
Date:
Subject: SQL Statement Missing From Log