Toad World® Forums

How to transpose rows to columns


#1

I would like to transpose rows to columns. From Image:
I’d like to transpose based on frequency_band and RRH_ANY_BAND with USIDN being the common value in initial data set. Some USIDN have 2 rows and some with 3 rows (not shown). In the image I forgot to do a mockup for Band3 .

I’d rather do using sql and not via the Pivot & Chart grid (unless I can get the statements from that grid)
Thanks!!!


#2

Does this blog help?


#3

Yes. Thanks.

Minor issue and related to special characters that are part of texts: My column names comprised of values that contain ; in the middle part of the string. How can I escape the semi-colon? Tried different ways and only way worked is single quote. But the single quotes appear as part of the column names. Here is the pivot statement:

pivot ( count(*) for frequency in ('1900; AWS ’ , ‘700; 5200’ , ‘AWS;1900’)


#4

Don’t you have to use an escape \ with the single quotes or brackets?
‘AT&T’
‘{AT&T}’
‘high-voltage’
‘{high-voltage}’


#5

Looks like the syntax I was using is sufficient (using single quotes). I did not need to use an escape character. Thanks