練習(xí)題

一、topN分析問題?

加偽列rownum行號(hào)的問題:

1:永遠(yuǎn)按照默認(rèn)的順序生成----在原表的順序下,跟排序無關(guān)

原因:臨時(shí)表的順序 create global temporary table****

特點(diǎn):當(dāng)會(huì)話或者事務(wù)結(jié)束的時(shí)候,臨時(shí)表中的數(shù)據(jù)自動(dòng)刪除

2:rownum只能使用<,<=,不能使用>,>=

select? rownum2, empno, ename, sal from (select rownum,empno,ename,sal from emp order by sal ?desc)where rownum2<=3;

二、查詢薪水高于本部門平均工資的員工

select e.empno, e.ename,e.sal ,d.AVGSAL from?

emp e, (select deptno,avg(sal) avgsal from emp group by deptno )d

WHERE E.deptno=d.deptno

and e.sal>d.avgsal;

相關(guān)子查詢:把主查詢中的某些值作為參數(shù)傳遞給子查詢

select e.empno,e.name,e.sal,(select avg(sal) from emp where deptno=e.deptno )avgsal

from emp e

where e.sal> (select avg(sal) from emp where deptno=e.deptno )

三、統(tǒng)計(jì)每年入職的員工人數(shù)

select count(*) total ,

sum(if to_year(to_date(hiredate))='1981' ?then i=i+1 else )"1981",

from emp


行轉(zhuǎn)列:

wm_concat(varchar2)-->組函數(shù)

例:select deptno,wm_concat(ename) namelist

from emp

group by deptno;

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容