From: | MT <m_tessier(at)sympatico(dot)ca> |
---|---|
To: | Pgsql <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Calculating total amounts per clientid |
Date: | 2003-12-13 21:41:03 |
Message-ID: | 20031213164103.49ca5e98.m_tessier@sympatico.ca |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thanks for responding. That was the tip I needed.
Regards,
Mark
On Sat, 13 Dec 2003 16:36:32 -0300
Martin Marques <martin(at)bugs(dot)unl(dot)edu(dot)ar> wrote:
> El Sáb 13 Dic 2003 16:21, MT escribió:
> > Hi,
> >
> > I have an invoicing system using postgresql. Each time a customer makes a
> purchase, a new record is inserted into the "cart" table. The "cart" table,
> among other things, contains a customer_id field and a total for the amount
> purchased on the particular invoice. Now what I'd like to do is to calculate
> the total invoices for each customer in a given time interval, then list
> those customers in descending order from most paying to least paying. Could
> someone give me some pointers on how to construct an sql statement that would
> flush out this data.
>
>
> First, lets see how to get the info you want:
> SELECT sum(invoice) AS total, customer_id FROM cart
> GROUP BY cuotomer_id;
>
> Now you can order it by the total column, and maybe give it a LIMIT, in case
> you have to many costumers. :-)
>
> --
> select 'mmarques' || '@' || 'unl.edu.ar' AS email;
> -----------------------------------------------------------------
> Martín Marqués | mmarques(at)unl(dot)edu(dot)ar
> Programador, Administrador, DBA | Centro de Telemática
> Universidad Nacional
> del Litoral
> -----------------------------------------------------------------
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Rawnsley | 2003-12-13 22:08:30 | Re: make error Mac OS X (ar: illegal option -- s) |
Previous Message | Keith C. Perry | 2003-12-13 21:24:29 | Re: tablespaces in 7.5? |