第34期Java面試題:commit運用,行列轉換,order by和group by

1、order by與group by的區別

order by 排序查詢、asc升序、desc降序

group by 分組查詢、having 只能用於group by子句、作用於組內,having條件子句可以直接跟函數表達式。使用group by 子句的查詢語句需要使用聚合函數。

2、commit運用

oracle的commit就是DML語句提交數據(這裡是釋放鎖不是鎖表),在未提交前你前面的操作更新的都是內存,沒有更新到物理文件中。

執行commit從用戶角度講就是更新到物理文件了,事實上commit時還沒有寫date file,而是記錄了redo log file,要從內存寫到data物理文件,需要觸發檢查點,由DBWR這個後臺進程來寫,這裡內容有點多的,如果不深究的話你就理解成commit即為從內存更新到物理文件。

3、行轉列、列換行怎麼轉

行轉列

第34期Java面試題:commit運用,行列轉換,order by和group by

1)使用decode函數

select name,

sum(decode(course, '語文', score, 0)) as 語文,

sum(decode(course, '數學', score, 0)) as 數學,

sum(decode(course, '英語', score, 0)) as 英語

from GRADE group by name;

2)使用case when語句

select name,

sum(case course when '語文' then score else 0 end) as 語文,

sum(case course when '數學' then score else 0 end) as 數學,

sum(case course when '英語' then score else 0 end) as 英語

from GRADE group by name;

select name,

sum(case when course='語文' then score else 0 end) as 語文,

sum(case when course='數學' then score else 0 end) as 數學,

sum(case when course='英語' then score else 0 end) as 英語

from GRADE group by name;

列轉行

第34期Java面試題:commit運用,行列轉換,order by和group by

select name, '語文' as course, cn_score as score from SC_GRADE

union all

select name, '數學' as course, math_score as score from SC_GRADE

union all

select name, '英語' as course, en_score as score from SC_GRADE

order by name;

oracle

第34期Java面試題:commit運用,行列轉換,order by和group by


分享到:


相關文章: