Pages

banner ads

Tuesday, May 7, 2013

Another complex sql operation example


postgresql array function

transpose a list of ids into a flat delimited row. the rOw could serve as a filter for subsequent queries:

SELECT
array_to_string(array_agg(trim(id)),’,')
FROM terms
Let’s say terms table has a list of ids:
id
1
2
3
after query we get:
1,2,3

Oracle way of doing this from my friend Darrin.
Here is the Oracle way to do this…

Select                     listagg(account_id,’,') within group (order by account_id asc)
From                      gg_account

You can also do

Select                      portfolio_id,
listagg(account_id,’,') within group (order by account_id asc)
From                      gg_account
Group by                portfolio_id

No comments:

Post a Comment