Doubts with PIVOT on Oracle

Asked

Viewed 22 times

2

Good afternoon,

I’m having trouble setting up a Pivot on the Oracle.

My query returns the categories in general, so I’m using the pivot to count the number of categories.

pivot(
count(CAT)
for CAT in (1 as cat1, 2 as cat2, 3 as cat3, 4 as cat4, 5 as cat5)
);

So far beauty, my problem is that I have categories above 5 and wanted to aggregate them in a single alias.

For example:

6 and 7 catX

8, 9 and 10 a Caty

But I don’t know how I put this on the anchor?

2 answers

2


Could in the query have the concatenation, sum, etc... of the categories:

select ...,
       6||7 as catx, 
       8||9||10 as caty
  from
   ...

And at your anchor make the reference.

pivot(
count(CAT)
for CAT in (1 as cat1, 2 as cat2, 3 as cat3, 4 as cat4, 5 as cat5, 6 as catx)
)

0

@David you killed the riddle.

I only had to put || in the pivot:

for CAT in (1 as cat1, 2 as cat2, 3 as cat3, 4 as cat4, 5 as cat5, 6||7 as catx, 8||9||10 as caty)

Worked!!!

Obg buddy =]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.