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



---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Reply via email to