oracle 11g 學習筆記 10_27

來源:互聯網
上載者:User
oracle複雜查詢 *在from子句中使用子查詢

.顯示高於自己部門平均工資的員工的資訊。

//1、查詢出各個部門的平均工資和部門號select deptno ,avg(sal) mysal from emp group by deptno;//2、把上面的查詢看作是一張子表a1,再結合emp表來進行多表查詢select a2.ename, a2.sal,a2.deptno, a1.mysal from emp a2,(select deptno ,avg(sal) mysal from emp group by deptno) a1 where a2.deptno = a1.deptno and a2.sal > a1.avg(sal);

注意:oracle 中給列取別名可以用as,但是給表取別名就不行了。
*分頁查詢

oracle分頁一共有三種方式。
其中一種是rownum分頁
.查詢分頁中序號是4~9 的員工的資訊,工資按降序來顯示。
步驟:

//1、從emp表查詢所有資訊,工資按降序來顯示select ename, sal from emp order by sal desc;//2、分頁顯示序號 <=9 的員工資訊select a1.*,rownum rn from (select ename,sal from emp order by sal desc) a1 where rownum <=9;//3、從分頁表中顯示 >=4 的員工資訊select * from (select a1.*, rownum rn from (select ename,sal from emp order by sal desc) a1 where rownum <=9) where rn >=4;//這裡不知道為什麼 最後的‘where rn >= 4’中的rn不能改成rownum,說不清楚了。
*用查詢結果建立新表

用這個命令可以快捷地建立一個表

create table mytable (id,name,sal,job,deptno) as select empno,ename,sal,job,deptno from emp;

這個可以建立了表,同時新表裡面也已經有了原來表的資料,可以用來做匯出表和在測試的時候不想對原
來的表修改刪除什麼的,也可以先匯出來在上面做測試。
*合并查詢
比較少用
二、建立資料庫

兩種方法:
1)通過oracle提供的嚮導工具

嚮導工具:oracle Database Configuration Assistant   
可以用來建立、刪除、組態管理資料庫。  
2)手工建立

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.