oracle練習題--來自芝加哥的有錢人

來源:互聯網
上載者:User

標籤:--   資訊   rom   tab   習題   esc   個人   and   order   

題目:從 scott 使用者的 emp/dept 表中,找到“來自芝加哥最有錢的那個人”。

 

思路:

1、這個人來自芝加哥

2、這個人是最有錢的,而且是芝加哥最有錢的

 

分兩步查詢:

1、找出所有來自芝加哥的人

2、從來自芝加哥的人中找到最有錢的那個

 

:1、開啟運行介面:window鍵+R-->輸入cmd

:2、通過sqlplus查詢工具查詢scott系統資料庫:C:\Users\Admin>sqlplus scott/zhang1622505426  --sqlplus  資料庫名/你的密碼  

:3、先看看這個scott資料庫裡包含哪幾個表:SQL> select table_name from user_tables;  

:4、查詢scott資料庫中的emp表:SQL> select * from emp;

:5、查詢scott資料庫中的dept表:SQL> select * from dept;

:6、為了使查詢的資料在一行顯示可以通過這個語句進行調整:SQL> set linesize 100

:7、查詢芝加哥所有的人:SQL>select e.* from emp e join dept d on (e.deptno=d.deptno) where d.loc=‘CHICAGO‘;  --join關鍵詞可以進行串連查詢,on後面指定串連的條件    

或 SQL>select e.* from emp e,dept d where d.deptno=e.deptno and d.loc=‘CHICAGO‘;

:8、通過max()函數的方式查詢芝加哥所有人中最有錢的人的所有資訊:SQL> select e.* from emp e,dept d where e.deptno=d.deptno and d.loc=‘CHICAGO‘ and sal=(select max(sal) from emp e,dept d where e.deptno=d.deptno and d.loc=‘CHICAGO‘);   --select max(sal) from emp e,dept d where e.deptno=d.deptno and d.loc=‘CHICAGO‘); 是查詢芝加哥最高的工資是多少   

   或:通過order by的方式查詢芝加哥所有人中最有錢的人的名字:SQL> select ename from (select e.*,d.* from emp e,dept d where e.deptno=d.deptno and d.loc=‘CHICAGO‘ order by sal desc) where rownum=1; --order by:排序;order by sal desc:根據工資的多少進行倒敘排序;rownum=1:表示取排序後的第一行;

oracle練習題--來自芝加哥的有錢人

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.