Обсуждение: SQL Function Question

Поиск
Список
Период
Сортировка

SQL Function Question

От
"TopShoTTa"
Дата:
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!



Re: SQL Function Question

От
Björn Lundin
Дата:
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