How does Oracle turn rows into columns?

the data found is like this. Is there any way to change the data into the following format? You still have to deal with

in the backend code.
Aug.17,2021

oracle row transfer column


if the value range of name is fixed, you can use the following statement:
select city, sum (cnt_1), sum (cnt_2), sum (cnt_3)
from (

)
select
  city, 
  decode(name, '', total, 0) as cnt_1,
  decode(name, '', total, 0) as cnt_2,
  decode(name, '', total, 0) as cnt_3
from t

)
group by city

Menu