Re: sum of agreggates in one SELECT?

Поиск
Список
Период
Сортировка
От John McKown
Тема Re: sum of agreggates in one SELECT?
Дата
Msg-id Pine.LNX.4.21.0009191308300.20327-100000@linux2.johnmckown.net
обсуждение исходный текст
Ответ на sum of agreggates in one SELECT?  (Louis-David Mitterrand <cunctator@apartia.ch>)
Ответы Re: sum of agreggates in one SELECT?  (Louis-David Mitterrand <cunctator@apartia.ch>)
Список pgsql-sql
Well, it's not a single SELECT, but why not use something like:

SELECT MAX(b.lot) AS quanity, max(p.price) AS price, p.login
INTO TEMPORARY TABLE temp1
FROM bid b, person p
WHERE b.auction_id=84 AND p.id=b.person_id
GROUP BY p.login 
ORDER BY max(price);

SELECT SUM(quanity) from temp1;

If you need the output from the original SELECT then you can print it by
simply doing:

SELECT * FROM temp1;

Hope this is of some use to you,
John 

On Tue, 19 Sep 2000, Louis-David Mitterrand wrote:

> Hello,
> 
> I have the following query/result:
> 
> auction=# select  max(b.lot) as quantity,max(b.price) as price,p.login
from bid b, person p  where b.auction_id = 84 and p.id = b.person_id group
by p.login order by max(price);
>  quantity | price |   login   
> ----------+-------+-----------
>         1 |  5000 | papy
>        12 |  5750 | cunctator
>         8 |  6000 | vindex
> (3 rows)
> 
> Now I would like to sum() all results from the quantity column and
> return it with one SELECT statement. Is that possible?
> 
> I am trying:
> 
> auction=# select sum(b.lot) from bid b, person p where b.auction_id = 84 and p.id = b.person_id ;
>  sum 
> -----
>   52
> (1 row)
> 
> But this is wrong because it sums all quantities. I don't know how to
> apply a valid WHERE clause in that case.
> 
> Thanks in advance for any help, cheers,
> 
> 
> 



В списке pgsql-sql по дате отправления:

Предыдущее
От: Josh Berkus
Дата:
Сообщение: Re: sum of agreggates in one SELECT?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Repeatable reads