From: | Devil™ Dhuvader <gibsosmat(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: need help in building a query |
Date: | 2008-11-06 16:15:44 |
Message-ID: | aaa67ada0811060815u7b5f3632j6b57e194b2339617@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
none can help me?
On Tue, Nov 4, 2008 at 9:08 PM, Devil™ Dhuvader <gibsosmat(at)gmail(dot)com> wrote:
> hi,
> I need some help in creating a sql.
> the problem is as below.
>
> assume that:
> I am a store keeper
> and I have the list of customer(user_id) transactions in my order table.
> schema: Orders(order_id, user_id, amount_paid, create_timestamp)
>
> I want to give discount of 10% for the customer who made orders of worth
> (sum) at least $500 in the least time from now (i.e last few days, but NOT
> ALL TIME LEAST TIME TO BUY $500 WORTH GOODS).
> and 9% discount for the customer who made $500 in second least time from
> now.
> and so on
>
> there is no time constraint.
> it customer could take any amount of time to make $500.
> the customer might not even made $500 bill till now in that case I should
> get the first date.
>
> the result can take upto the first entry time of the table itself.
>
> in short its like sum up entries of each user in order table backwards (i.e
> from last entry to the first) and find the entry that has sum > $500.
> If there is some user who didnt even make 500 till now in my shop return
> the first date of transaction/order.
>
> can anyone help me on this?
From | Date | Subject | |
---|---|---|---|
Next Message | Harold A. Giménez Ch. | 2008-11-06 17:10:24 | Re: need help in building a query |
Previous Message | Scott Marlowe | 2008-11-05 17:14:42 | Re: |