SQL Function Question

Started by TopShoTTaabout 24 years ago2 messagesgeneral
Jump to latest
#1TopShoTTa
topshotta@shotta.com

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!

#2Björn Lundin
bjorn.lundin@swipnet.se
In reply to: TopShoTTa (#1)
Re: SQL Function Question

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