Re: Problem with select statement

Поиск
Список
Период
Сортировка
От Ragnar Hafstað
Тема Re: Problem with select statement
Дата
Msg-id 1108942979.17842.3.camel@localhost.localdomain
обсуждение исходный текст
Ответ на Problem with select statement  (phil campaigne <pcampaigne@charter.net>)
Список pgsql-general
On Sun, 2005-02-20 at 18:18 -0500, phil campaigne wrote:
> Yes Gnari it works now!
> all I had to do in addition to your advice was  alias the sub select:
>
> hardwoodthunder=# select
> player_number,player_name,cum_score,sum(a),sum(c),sum(t) from ( select
> player_number, player_name, cum_score, (select player_points where
> aspect='A') as A ,(select player_points where aspect='C') as C, (select
> player_points where aspect='T') as T from (select
> * from player as a,teamshare as b where a.player_number=b.player) as c)
> as B group by player_number, player_name, cum_score;
>  player_number | player_name | cum_score | sum  | sum  | sum
> ---------------+-------------+-----------+------+------+-----
>  40            | R. Perkins  |         4 | 0.27 | 0.33 |
>  42            | S. Randolph |         2 | 0.54 | 0.66 | 0.8
>  42            | S. Randolph |         4 | 0.27 | 0.33 | 0.8
> (3 rows)
>
> Now what about the total?  How do I add another column that is the sum
> of a,c,t?
>

maybe something like:
select player_number,player_name,cum_score, suma,sumc,sumt,
coalesce(suma,0)+coalesce(sumc,0)+coalesce(sumt,0) as sumtotal
from ( select
player_number,player_name,cum_score,sum(a) as a,sum(c) as c,sum(t) as t from ( select
player_number, player_name, cum_score, (select player_points where
aspect='A') as A ,(select player_points where aspect='C') as C, (select
player_points where aspect='T') as T from (select
* from player as a,teamshare as b where a.player_number=b.player) as c)
as B group by player_number, player_name, cum_score) as foo);

gnari



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

Предыдущее
От: phil campaigne
Дата:
Сообщение: Problem with select statement
Следующее
От: phil campaigne
Дата:
Сообщение: Re: Problem with select statement