oracle中複雜sql查詢語句詳解 (1/4)

來源:互聯網
上載者:User

1.查詢語句的使用
使用 select語句和子查詢(subquery)可以從一個或多個表,視圖,實體試圖中返回資料.
 
1.1相互關聯的子查詢
可以將子查詢(as subquery)或in或exists當成where的一個條件的一部分,這樣的查詢稱為子查詢
  .where中可以包含一個select語句的子查詢
  .where中可以包含in,exists語句
  .最多可以嵌套16層
  .層次過多會影響效能
  [例]簡單子查詢執行個體
  查詢是否有的專家既以研究所的名義來申請基金項目,又以大學係為單位申請項目
  (按規定只能以一個單位來申請)
  sql> create table univ_subject
  2    (
  3       name                 varchar2(12) not null,
  4       per_id                number     not null,
  5      dept_name       varchar2(20)            
  6    );
  sql> insert into univ_subject  values('gaoqianjing',1001,'資訊工程系');
  sql> insert into univ_subject  values('wangbing',1002,'物理系');
  sql> insert into univ_subject  values('liming',1003,'化學系');
  ===============
   sql> create table  colle_subject
  2     (
  3              colle_name    varchar2(20),
  4              per_id              number
  5     );
  sql> insert into colle_subject values('電子研究所',1001);
  sql>  insert into colle_subject values('物理研究所',1005);
  ================
  sql> select name,per_id,dept_name from univ_subject where per_id in
  2    (select per_id from colle_subject);

  name            per_id   dept_name
  ------------          ---------     --------------------
  gaoqianjing  1001      資訊工程系

首頁 1 2 3 4 末頁

聯繫我們

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