Oracle
 sql >> Teknologi Basis Data >  >> RDS >> Oracle

tabel kueri pivot oracle sql

Ini dia:

with w(time, ID, Page) as
(
  select '9:30', 1, 'name1' from dual
  union all
  select '9:30', 1, 'name2' from dual
  union all
  select '9:30', 1, 'name3' from dual
  union all
  select '9:30', 2, 'name4' from dual
  union all
  select '9:30', 2, 'name5' from dual
  union all
  select '7:30', 3, 'name1' from dual
)
select *
from
(
  select w.time, w.id, w.page, row_number() over (partition by w.time, w.id order by w.page) rnk
  from w
)
pivot (max(page) for rnk in (1 as page1, 2 as page2, 3 as page3))
order by 1, 2
;

Ini memberikan:

TIME    ID    PAGE1    PAGE2    PAGE3
7:30    3     name1        
9:30    1     name1    name2    name3
9:30    2     name4    name5    



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. PEMBARUAN tentang tampilan pelestarian kunci di Oracle memunculkan ORA-01779

  2. Fungsi Oracle Autoincrement:Pemicu atau Oracle JDBC CallableStatement di 11.2?

  3. Bagaimana cara mengatasi masalah pemetaan parameter kueri SQL saat menggunakan penyedia Oracle OLE DB?

  4. orakel | hapus catatan duplikat

  5. Pernyataan pembaruan Oracle dengan fungsi grup