Re: Query Problem
| От | Joe Conway |
|---|---|
| Тема | Re: Query Problem |
| Дата | |
| Msg-id | 3FB039BB.9090103@joeconway.com обсуждение исходный текст |
| Ответ на | Query Problem (Abdul Wahab Dahalan <wahab@mimos.my>) |
| Список | pgsql-sql |
Abdul Wahab Dahalan wrote:
> If I've a table like below.
>
>> kk kj pngk vote
>> 01 02 c 10
>> 01 02 b 5
> How do I make a query so that I can get a result
> like this?
>>
>> kk kj pngk vote
>> 01 02 c,b 15
>>
create or replace function accum_text(text, text) returns text as
'select case when $1 = '''' then $2 else $1 || '','' || $2 end' language
sql;
CREATE AGGREGATE concat(BASETYPE = text, SFUNC = accum_text, STYPE =
text, INITCOND = '');
create table t(kk text, kj text, pngk text, vote int);
insert into t values('01','02','c',10);
insert into t values('01','02','b',5);
regression=# select kk, kj, concat(pngk), sum(vote) from t group by kk, kj; kk | kj | concat | sum
----+----+--------+----- 01 | 02 | c,b | 15
(1 row)
HTH,
Joe
В списке pgsql-sql по дате отправления: