Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Oracle row-column conversion

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The first is to use the decode, a very common way to write:

select sname,sum(decode(course,'language', score,0)) "language",sum(decode(course,' math', score,0)) "mathematics",sum(decode(course,'english', score,0)) "english" from score group by sname;

The second is a function pivot using oracle, which is a column rotation. There is also an unpivot, which is row to column.

select * from (select sname,course,score from score)

pivot(

sum(score)

for course in(

'language' as "language",

'mathematics' as 'mathematics,'

'English' as "English"))

order by sname;

Data source:

SNAME COURSE SCORE

-------------------

Bill Language 80

Bill Math 90

Bill English 92

Jim Language 78

Jim Maths 88

Jim English 98

Comparison of the two results:

SNAME Chinese Mathematics English

------------------------------

Bill 80 90 92

Jim 78 88 98

SNAME Chinese Mathematics English

-------------------------------

Bill 80 90 92

Jim 78 88 98

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report