Re: need help in building a query - Mailing list pgsql-sql

From Devil™ Dhuvader
Subject Re: need help in building a query
Date
Msg-id aaa67ada0811080857x7bc3736qf0c664613b89a11f@mail.gmail.com
Whole thread Raw
In response to Re: need help in building a query  (Frank Bax <fbax@sympatico.ca>)
List pgsql-sql
yes, I am picking up the specific transaction (order_id) so that I can pickup the create_timestamp and sort it
descending.<br/>that will list me those users who did transaction more than 500 in the least time.<br />then I can give
discountfor top 10 users<br /> expected output: user_id, create_timestamp(desc) with limit 10.<br />then I will give
discountof 10%, 9%, .. etc.<br /><br />if you know ageing credit. its just like that.<br /><br /><div
class="gmail_quote">OnSat, Nov 8, 2008 at 2:30 AM, Frank Bax <span dir="ltr"><<a
href="mailto:fbax@sympatico.ca">fbax@sympatico.ca</a>></span>wrote:<br /><blockquote class="gmail_quote"
style="border-left:1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div
class="Ih2E3d">Devil™Dhuvader wrote:<br /><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204,
204);margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">  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 .<br /><br /> ex:<br /> Orders(order_id,
user_id,amount_paid, create_timestamp)<br /> values:<br /> (1, 1, 100, 1)<br /> (2, 1, 300, 2)<br /> (3, 2, 100, 2)<br
/>(4, 2, 100, 3)<br /> (5, 1, 100, 4)<br /> (6, 1, 200, 5)<br /> (7, 2, 150, 5)<br /><br /> for user 1: the order_id =
2<br/> for user 2: the order_id = 3 (coz he couldnt make 500)<br /></blockquote><br /><br /></div> I might also take a
crackat the SQL if I understood the question; but I still don't know what you want.  You're initial question indicated
youwere trying to calculate the proper discount for each customer.  This example mentions neither customers nor
discountsat all and appears to be looking for a specific transaction instead.<br /><br /> Frank<br /><font
color="#888888"><br/> -- <br /> Sent via pgsql-sql mailing list (<a href="mailto:pgsql-sql@postgresql.org"
target="_blank">pgsql-sql@postgresql.org</a>)<br/> To make changes to your subscription:<br /><a
href="http://www.postgresql.org/mailpref/pgsql-sql"target="_blank">http://www.postgresql.org/mailpref/pgsql-sql</a><br
/></font></blockquote></div><br/> 

pgsql-sql by date:

Previous
From: Frank Bax
Date:
Subject: Re: need help in building a query
Next
From: "Devil™ Dhuvader"
Date:
Subject: Re: need help in building a query