從頭開始學Oracle 行轉列

2021-10-05 02:50:43 字數 1478 閱讀 7910

with temp as(

select '大宇' name ,'語文' subject,'85' score from dual union all

select '大宇' name ,'數學' subject,'81' score from dual union all

select '小宇' name ,'語文' subject,'77' score from dual union all

select '小宇' name ,'數學' subject,'72' score from dual union all

select '小大宇' name ,'語文' subject,'58' score from dual

)select name,

-- 如果subject是語文的話,這一列取score,如果score為空則取0

max(decode(subject, '語文', score, '0')) as score_語文,

max(decode(subject, '數學', score, '0')) as score_數學

select '四川省' nation ,'成都市' city,'第一' ranking from dual union all

select '四川省' nation ,'綿陽市' city,'第二' ranking from dual union all

select '四川省' nation ,'德陽市' city,'第三' ranking from dual union all

select '四川省' nation ,'宜賓市' city,'第四' ranking from dual union all

select '湖北省' nation ,'武漢市' city,'第一' ranking from dual union all

select '湖北省' nation ,'宜昌市' city,'第二' ranking from dual union all

select '湖北省' nation ,'襄陽市' city,'第三' ranking from dual

)select nation,

max(decode(ranking, '第一', city, '')) as 第一,

max(decode(ranking, '第二', city, '')) as 第二,

max(decode(ranking, '第三', city, '')) as 第三,

max(decode(ranking, '第四', city, '')) as 第四

from temp group by nation;

從頭開始學Oracle 偽列

在oracle資料庫中,有乙個表示行中唯一特性的識別符號,該昂識別符號的名稱為rowid。由於該列實際並不定義在表中,所以也被稱之為偽列。偽列rowid的長度是18位,包含該行資料在oracle資料庫中的實體地址。select rowid 偽列,rownum是乙個序列,會為sql查詢結果自動增加乙個...

從頭開始學Oracle 時間函式

引數,字串型別。oracle中使用時間進行比較,需要轉成時間date型別。如果引數傳遞的是 字串 需要使用to date 字串日期,format 格式化字串成date型別。然後再進行時間的對比 開始時間 符合條件的記錄 結束時間 t.cjrq to date concat 2020 11 15 00...

從頭開始學JDK String

目錄 string 倒序 string 建構函式 string equals string 記憶體 string hashcode string startswith string endwith string indexof string lastindexof string substring ...