Re: [SQL] need help in building a query
none can help me? On Tue, Nov 4, 2008 at 9:08 PM, Devil™ Dhuvader <[EMAIL PROTECTED]> 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?
Re: [SQL] need help in building a query
I personally would help if I understood what you need. I'm sure others feel the same way. Provide DDL, sample data, and expected result of the query. Maybe you'll have better luck... On Thu, Nov 6, 2008 at 11:15 AM, Devil™ Dhuvader <[EMAIL PROTECTED]>wrote: > none can help me? > > On Tue, Nov 4, 2008 at 9:08 PM, Devil™ Dhuvader <[EMAIL PROTECTED]>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? > > >
[SQL] Finding all tables that have foreign keys referencing a table
Hi. I see the last comment here suggests a solution for $subject: http://www.postgresql.org/docs/8.1/interactive/ddl-constraints.html But it turns out it assumes constraint_name is unique, which is not the case. It is only unique pr. table. In other words, it produces a lot of false results. I'm trying to make a function which finds all my old "$1" constraints and replaces those names with proper names (_fkey). So - anybody who knows a good solution for how to find all tables with constraint-names that have foreign keys referencing a table's particluar colum? -- Andreas Joseph Krogh <[EMAIL PROTECTED]> Senior Software Developer / CEO +-+ OfficeNet AS| The most difficult thing in the world is to | Karenslyst Allé 11 | know how to do a thing and to watch | PO. Box 529 Skøyen | somebody else doing it wrong, without | 0214 Oslo | comment.| NORWAY | | Tlf:+47 24 15 38 90 | | Fax:+47 24 15 38 91 | | Mobile: +47 909 56 963 | | +-+ -- Sent via pgsql-sql mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
