Connecting Tech Pros Worldwide Forums | Help | Site Map

How to writ function in postgres?

Newbie
 
Join Date: Apr 2008
Location: India
Posts: 2
#1: Apr 4 '08
Plz can any one help me to write function in postgres

i have a table with two columns
for example student class and student name

the table Data is like this
STU_class Name
1 Ann
2 JAck
3 Dickson
1 Donald

but the report i need is in the following format

Class Name
1 Ann,Donald
2 JacK
3 Dickson

can anyone help me to generate this report

Thanks in advance

Moderator
 
Join Date: Dec 2006
Location: Europe
Posts: 292
#2: Apr 4 '08

re: How to writ function in postgres?


Quote:

Originally Posted by annielucinda

Plz can any one help me to write function in postgres

i have a table with two columns
for example student class and student name

the table Data is like this
STU_class Name
1 Ann
2 JAck
3 Dickson
1 Donald

but the report i need is in the following format

Class Name
1 Ann,Donald
2 JacK
3 Dickson

can anyone help me to generate this report

Thanks in advance

Suppose table name is test, i think it is the solution
Expand|Select|Wrap|Line Numbers
  1. select distinct  i as class, array_to_string((array(select j from test where i=k.i)),',') as name from test k;
  2.  
Reply


Similar PostgreSQL Database bytes