Table name is t1
. Field name is name1
. name1 has value like this
-------------------------------------------+
+ name1 +
--------------------------------------------
| "a_2013,AcMaster,Master" |
| "b_2014,AcMaster,Master" |
| "c_2013,a_AcMaster,a_Master" |
| "d_2014,a_AcMaster,a_Master" |
|__________________________________________|
But i want to get reslut like this
master acmaster text
Master AcMaster a_2013,b_2014
a_Master a_Master c_2013,d_2014
So i try like this
select (string_to_array(schemaname,',')) [3] as master,(string_to_array(schemaname,','))
[2] as acmaster,(string_to_array(schemaname,',')) [1] from appsetup.company2
c2,appsetup.company1 c1,appsetup.companygroup cg where c1.compno=c2.compno and
cg.compgroupno=c1.compgroupno and c1.compno in (3,2) group by
string_to_array(schemaname,',')) [3],
(string_to_array(schemaname,',')) [2],cg.compgroupno,schemaname order by
cg.compgroupno
But its return
master acmaster text
Master AcMaster ["a_2013","b_2014"]
a_Master a_Master ["c_2013","d_2014"]
How to get my wanted result?
Am using Postgresql 9.3
You can try this:
select string_agg(name1, ',') as Name1s
from t1
string_agg
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With