I
I
ivandao2019-10-21 11:10:52
SQL
ivandao, 2019-10-21 11:10:52

Is it possible to somehow dynamically form a pivot?

Is it possible to somehow dynamically form what is after FOR IN ?

select * from (
   select times_purchased as "Puchase Frequency", state_code
   from customers t
)
pivot 
(
   count(state_code)
   for state_code in ('NY' as "New York",'CT' "Connecticut",'NJ' "New Jersey",'FL' "Florida")
)
order by 1

Here are the values
'NY' as "New York",'CT' "Connecticut",'NJ' "New Jersey",'FL' "Florida"
I have them stored in a separate cities table , I can pull them out with select, so I don’t really want to write them explicitly in pivot.
I tried to substitute such a query after FOR :
SELECT
  LISTAGG( city , ',') WITHIN GROUP (ORDER BY ID) city
FROM cities

Oracle, of course, did not gobble it up.
How can you do?
https://www.oracle.com/technical-resources/article...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TheRonCronix, 2019-10-21
@TheRonCronix

Not sure, but most likely not. Can be solved through dynamic sql.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question