Re: SQL Function Question

From: Bjrn Lundin <bjorn(dot)lundin(at)swipnet(dot)se>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL Function Question
Date: 2002-03-11 20:54:15
Message-ID: 20020311215415.57f104f3.bjorn.lundin@swipnet.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, 09 Mar 2002 18:13:59 GMT
"TopShoTTa" <topshotta(at)shotta(dot)com> wrote:

> I'm new to SQL and taking a course in it right now. One of the things that
> I need to do for an assignment is display sum, avg, max, and min amounts
> multiplied by quantity. All in one table. Here is what I'm doing but not
> correct for some reason.
>
> select (sum(price)+avg(price)+max(price)+min(price)) * quantity
> from order;
>
> I get error - not a single group function. My book is very limited on the
> information so I thought I'd post here.
>
> Thanks!
>
>

1, Your output will go in 1 column only. This is proberbly what you wan't

select sum(price) * quantity, avg(price) * quantity, max(price) * quantity, min(price) * quantity
from order;

2, In the above, I am trying to mulitply something grouped with something not grouped.
What does sum(price) * quantity mean ? What quantity is to be used (the sum(price) is
one row but quantity are (or could be) many rows.
You need do decide what quantity to use, proberbly by grouping whit quantity.

select sum(price) * quantity, avg(price) * quantity, max(price) * quantity, min(price) * quantity
from order, group by quantity;

/Björn

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dan Langille 2002-03-11 21:08:23 Re: using syslog to capture RAISE notices
Previous Message Patrick L. Nolan 2002-03-11 20:52:14 Looking for information about rtree index