Re: SQL Function Question - Mailing list pgsql-general

From Björn Lundin
Subject Re: SQL Function Question
Date
Msg-id 20020311215415.57f104f3.bjorn.lundin@swipnet.se
Whole thread Raw
In response to SQL Function Question  ("TopShoTTa" <topshotta@shotta.com>)
List pgsql-general
On Sat, 09 Mar 2002 18:13:59 GMT
"TopShoTTa" <topshotta@shotta.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






pgsql-general by date:

Previous
From: Michael Robinton
Date:
Subject: Re: postgres 7.2 make check problem
Next
From: "otisg"
Date:
Subject: Re: Fast vector similarity metric