Re: SQL Function Question

Поиск
Список
Период
Сортировка
От Björn Lundin
Тема Re: SQL Function Question
Дата
Msg-id 20020311215415.57f104f3.bjorn.lundin@swipnet.se
обсуждение исходный текст
Ответ на SQL Function Question  ("TopShoTTa" <topshotta@shotta.com>)
Список 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 по дате отправления:

Предыдущее
От: Michael Robinton
Дата:
Сообщение: Re: postgres 7.2 make check problem
Следующее
От: "otisg"
Дата:
Сообщение: Re: Fast vector similarity metric