Skip site navigation (1) Skip section navigation (2)

Re: need help in building a query

From: Devil™ Dhuvader <gibsosmat(at)gmail(dot)com>
To: "Frank Bax" <fbax(at)sympatico(dot)ca>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: need help in building a query
Date: 2008-11-08 16:57:12
Message-ID: aaa67ada0811080857x7bc3736qf0c664613b89a11f@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-sql
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) with limit 10.
then I will give discount of 10%, 9%, .. etc.

if you know ageing credit. its just like that.

On Sat, Nov 8, 2008 at 2:30 AM, Frank Bax <fbax(at)sympatico(dot)ca> wrote:

> Devil™ Dhuvader wrote:
>
>>  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 .
>>
>> ex:
>> Orders(order_id, user_id, amount_paid, create_timestamp)
>> values:
>> (1, 1, 100, 1)
>> (2, 1, 300, 2)
>> (3, 2, 100, 2)
>> (4, 2, 100, 3)
>> (5, 1, 100, 4)
>> (6, 1, 200, 5)
>> (7, 2, 150, 5)
>>
>> for user 1: the order_id = 2
>> for user 2: the order_id = 3 (coz he couldnt make 500)
>>
>
>
> I might also take a crack at the SQL if I understood the question; but I
> still don't know what you want.  You're initial question indicated you were
> trying to calculate the proper discount for each customer.  This example
> mentions neither customers nor discounts at all and appears to be looking
> for a specific transaction instead.
>
> Frank
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

In response to

pgsql-sql by date

Next:From: Devil™ DhuvaderDate: 2008-11-08 17:12:38
Subject: Re: need help in building a query
Previous:From: Frank BaxDate: 2008-11-07 21:00:40
Subject: Re: need help in building a query

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group