SQL1-ch5 顯示多個表格的資料. 題號  80 題: 34 、 57 、 71 、 72  140 題: 18 、 25 、 62 、 97 、 115 、 131.

Slides:



Advertisements
Similar presentations
SQL1-ch7 集合運算 1. 題號  80 題: 50 、 55 、 62  140 題: 41 、 61 、
Advertisements

Installment 7 Tables With No Column Presented by rexmen 2001 資管所.林彥廷.
SQL2-ch1 控制使用者存取. 題號  80 題: 14 、 22 、 40 、 42 、 52  140 題: 9 、 40 、 103.
SQL1-ch2 限制和排序資料. 考古題題號  80 題: 27 、 51  140 題: 23 、 58 、 70.
SQL1-ch11 使用資料說明視觀表 (Data Dictionary) 管理物件. 題號  80 題: 6 、 64  140 題: 105.
Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
Introduction to Java Programming Lecture 13 Classes I OO Programming.
建立使用案例敘述 --Use Case Narrative
“Rule” By OX. By Check CREATE TABLE 員工薪資 ( 編號 int IDENTITY PRIMARY KEY, 薪資 smallmoney, CHECK ( 薪資 > 0 AND 薪資
T-SQL 運算子介紹 11/29. 運算子的總類 指定運算子 算術運算子 比較運算子 邏輯運算子 位元運算子 字串連結運算子 單一運算元運算子.
BY OX. 檢視表與資料表的差異性 查詢 (query) 檢視表 (View) 的紀錄,是經由查詢 (query) 而來,而檢 視表的資料來源可以是單一資料表或是多資料表,甚 至其他檢視表 但檢視表中的紀錄只存在資料表中.
5 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
各種線上電子資源的特異功能 STICnet 的 SDI 專題訂閱服務 2003/4/28 修改. 無論校內外皆可使用。連線至
Introduction to Java Programming Lecture 17 Abstract Classes & Interfaces.
第 5 章 深入 Response 物件 製作. 網頁的轉向與強制輸出 - 讓網頁轉彎的 Redirect 敘述 運用 Response 物件的 Redirect 方法,將瀏覽器顯 示的網頁,導向至其他網頁,語法如下: Response.Redirect 網頁路徑與名稱 此網頁路徑與名稱  若是導向到同一台.
資料庫程式設計與系統管理 SQL Server 2005 Express 第六章 進階資料庫設計.
國立聯合大學 資訊管理學系 陳士杰老師 SQL*Plus 與 iSQL*Plus 簡介. 國立聯合大學 資訊管理學系 資料庫系統課程 ( 陳士杰 ) 2 啟動 SQL*Plus 與 iSQL*Plus 方式 Windows 平台.
Chapter 10 m-way 搜尋樹與B-Tree
Hung-Hsiang WuWindows Processing Design1 Chapter10 資料庫元件應用二 Table and Query 元件不同處: 提供 SQL (Structured Query Language) 語法 各種資料庫軟體大都支援 SQL 語法  Oracle 、
5 重複迴圈 5.1 增減運算符號 增量運算符號 減量運算符號
SQL 進階查詢.
Visual C++重點複習.
: Place the Guards ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11080: Place the Guards 解題者:陳盈村 解題日期: 2008 年 3 月 26 日 題意:有一個國王希望在他的城市裡佈置守衛,
C 語言練習題 2010/12/2. C 程式的格式 一、 C 程式的格式 (1). /* …. */ 是 C 程式的 ______ main() 的內容是由敘述構成的 (2). 敘述要以 __ 為結束符號 (3). 變數、函數都要做 ____ 的宣告 (4). ‘=’ 是 ____ 用的算符 (5).
實體關係模型 (ER Model).
Displaying Data from Multiple Tables. Obtaining Data from Multiple Tables Sometimes you need to use data from more than one table. In the example, the.
Objectives After completing this lesson, you should be able to do the following: Write SELECT statements to access data from more than one table using.
4 Copyright © Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
4 Copyright © Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
Sections 3 – Joins & Hierarchical Queries
Copyright © 2004, Oracle. All rights reserved. Lecture 6 Displaying Data from Multiple Tables ORACLE.
Basisdata Pertanian. After completing this lesson, you should be able to do the following:  Write SELECT statements to access data from more than one.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts 在 E-R 圖中的符號.
Join, Subqueries and set operators. Obtaining Data from Multiple Tables EMPLOYEES DEPARTMENTS … …
4 Copyright © Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
SQL1-ch8 操作資料 (DML) 1. 題號  80 題: 47 、 67  140 題: 12 、 49 、 50 、 55 、 79 、 80 、 89 、
Copyright © 2004, Oracle. All rights reserved. D ISPLAYING D ATA FROM M ULTIPLE T ABLES.
5 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
ORACLE SQL Fundamental II 4-5 章重點 Chap 4 Managing Objects with Data Dictionary Views Chap 5 Manipulating Large Data Sets 1. subqueries ( inline view :
5 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
Intermediate SQL: Aggregated Data, Joins and Set Operators.
SQL1-ch10 其他綱要物件. 題號  80 題: 5 、 9 、 18 、 32 、 38 、 41 、 44 、 54 、 77  140 題: 76 、 78 、 120 、 132.
Database Programming Sections 4 – Joins. Marge Hohly2 Overview  Oracle Proprietary Joins (8i and prior): Cartesian Product Equijoin Non-equijoin Outer.
Database Programming Section 15 – Oracle Proprietary Join Syntax and Review 1.
SQL1-ch1 使用SQL SELECT 敘述句擷取資料.
SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127.
SQL2-ch4 群組相關資料以產生報表. 題號  80 題: 11 、 20 、 43 、 59 、 70 、 80  140 題: 14 、 88 、 113.
SQL1-ch4 群組函數與聚總資料. 題號  80 題: 33 、 39  140 題: 10 、 59 、 95 、 110.
Database Programming Sections 3 – Oracle Joins. Marge Hohly2 Obtaining Data from Multiple Tables: Using Joins.
6 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using Subqueries.
In this session, you will learn to: Query data by using joins Query data by using subqueries Objectives.
SQL1-ch9 使用 DDL 建立與管理表格 1. 題號  80 題: 63 、 76  140 題: 6 、 24 、 44 、 71 、 77 、 92 2.
4 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
1 Copyright © 2009, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Displaying Data from Multiple Tables. Objectives After completing this lesson, you should be able to do the following: –Write SELECT statements to access.
4 Copyright © Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
6 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using Subqueries.
Displaying Data from Multiple Tables
Oracle Join Syntax.
Displaying Data from Multiple Tables
Displaying Data from Multiple Tables
Displaying Data from Multiple Tables
Displaying Data from Multiple Tables Using Joins
多表查询 Schedule: Timing Topic 55 minutes Lecture 55 minutes Practice
Oracle Join Syntax.
SQL2-ch3 操控大型資料集.
Oracle Join Syntax.
Displaying Data from Multiple Tables
Displaying Data from Multiple Tables
Presentation transcript:

SQL1-ch5 顯示多個表格的資料

題號  80 題: 34 、 57 、 71 、 72  140 題: 18 、 25 、 62 、 97 、 115 、 131

表格合併  內部合併:只列出兩表格相符欄位資料  自然合併 -Natural Join  合併 -Join using 、 on  外部合併:可列出不符合欄位資料  Left outer join  Right outer join

表格合併  自然合併 (Natural Join)  兩表格中具有相同名稱、型態的資料欄位  若欄位名稱相同,但型態不同則回傳錯誤

使用 Using 子句  Using 可指定欲合併的欄位 ( 名稱須相同 )  Natural join 須改成 Join … Using …  欄位不可加上表格名稱或別名

Q34/80 View the Exhibit and examine the structure of the ORDERS and ORDER_ITEMS tables. Evaluate the following SQL statement: SELECT oi.order_id, product_id, order_date FROM order_items oi JOIN orders o USING(order_id); Which statement is true regarding the execution of this SQL statement? 6

Q34 表格合併 (SQL1 ch5) A. The statement would not execute because table aliases are not allowed in the JOIN clause. B. The statement would not execute because the table alias prefix is not used in the USING clause. C. The statement would not execute because all the columns in the SELECT clause are not prefixed with table aliases. D. The statement would not execute because the column part of the USING clause cannot have a qualifier in the SELECT list. (P5-11) SELECT oi.order_id, product_id, order_date FROM order_items oi JOIN orders o USING(order_id); SELECT oi.order_id, product_id, order_date FROM order_items oi JOIN orders o USING(order_id); 7

使用 On 子句  使用 On 可描述合併的條件 ( 欄位名可不同 )  From tableA join tableB on ( 條件 )  若欄位名稱相同,須加上表格名稱或別名

使用 On 子句  On 子句的變化

練習  查出每位員工的姓名、部門名稱與城市。  姓名 (last_name) 在會員表格 (employees) 中  部門名稱 (department_name) 在部門表格 (departments) 中  城市 (city) 在位置表格 (locations) 中

Q71/80 View the Exhibit and examine the structure of the EMP and SALGRADE tables. You want to display the names of all employees whose salaries belong to GRADE 5. Which SQL statements give the required output? (Choose all that apply) 11

12

A. SELECT ename FROM emp JOIN salgrade USING (sal BETWEEN losal AND hisal) AND grade = 5; B. SELECT ename FROM emp e JOIN salgrade s ON (e.sal BETWEEN s.losal AND s.hisal AND s.grade = 5); C. SELECT ename FROM emp e JOIN salgrade s ON (e.sal BETWEEN s.losal AND s.hisal) AND s.grade = 5; D. SELECT ename FROM emp e JOIN salgrade s ON (e.sal BETWEEN s.losal AND s.hisal) WHERE s.grade=5; E. SELECT ename FROM emp e JOIN salgrade s WHERE e.sal BETWEEN s.losal AND s.hisal AND s.grade = 5; 13

外部合併  希望可顯示出未符合的資料

Q57/80 View the Exhibit and examine the description of the ORDER_ITEMS and PRODUCT_INFORMATION tables. The ORDER_ITEM table has records pertaining to details for each product in an order. The PRODUCT_INFORMATION table has records for all the products available for ordering. Evaluate the following SQL statement: SELECT oi.order_id, pi.product_id FROM order_items oi RIGHT OUTER JOIN product_information pi ON (oi.product_id=pi.product_id); Which statement is true regarding the output of this SQL statement? 15

A. The query would return the ORDER_ID and PRODUCT_ID for only those products that are ordered. B. The query would return the ORDER_ID and PRODUCT_ID for the products that are ordered as well as for the products that have never been ordered. C. The query would return the ORDER_ID and PRODUCT_ID for the products that are ordered but not listed in the PRODUCT_INFORMATION table. D. The query would return the ORDER_ID and PRODUCT_ID for those products that are ordered as well as for the products that have never been ordered, and for the products that are not listed in the PRODUCT_INFORMATION table. SELECT oi.order_id, pi.product_id FROM order_items oi RIGHT OUTER JOIN product_information pi ON (oi.product_id=pi.product_id); SELECT oi.order_id, pi.product_id FROM order_items oi RIGHT OUTER JOIN product_information pi ON (oi.product_id=pi.product_id); 16

Q72/80 View the Exhibit and examine the structure of the DEPARTMENTS and LOCATIONS tables. You want to display all the cities and the corresponding departments in them, if any. Which query would give you the required output? 17

18

A. SELECT location_id LOC, city, department_id DEPT FROM locations LEFT OUTER JOIN departments USING (location_id); B. SELECT location_id LOC, city, department_id DEPT FROM locations RIGHT OUTER JOIN departments USING (location_id); C. SELECT l.location_id LOC, l.city, d.department_id DEPT FROM locations l LEFT OUTER JOIN departments d USING (location_id); D. SELECT l.location_id LOC, l.city, d.department_id DEPT FROM locations l FULL OUTER JOIN departments d USING (location_id); 19

Q25/140( 可略 ) View the Exhibit and examine the structure of the ORDER_ITEMS and ORDERS tables. You are asked to retrieve the ORDER_ID, PRODUCT_ID, and total price (UNIT_PRICE multiplied by QUANTITY), where the total price is greater than 50,000. You executed the following SQL statement: SELECT order_id, product_id, unit_price*quantity "Total Price" FROM order_items WHERE unit_price*quantity > NATURAL JOIN orders; Which statement is true regarding the execution of the statement?

A. The statement would execute and provide the desired result. B. The statement would not execute because the ON keyword is missing in the NATURAL JOIN clause. C. The statement would not execute because the WHERE clause is before the NATURAL JOIN clause. D. The statement would not execute because the USING keyword is missing in the NATURAL JOIN clause. SELECT order_id, product_id, unit_price*quantity "Total Price" FROM order_items WHERE unit_price*quantity > NATURAL JOIN orders;

Q62/140( 可略 ) View the Exhibit and examine the description of the EMPLOYEES and DEPARTMENTS tables. You want to display the LAST_NAME for the employees, LAST_NAME for the manager of the employees, and the DEPARTMENT_NAME for the employees having 100 as MANAGER_ID. The following SQL statement was written: SELECT m.last_name "Manager", e.last_name "Employee", department_name "Department" FROM employees m JOIN employees e ON (m.employee_id = e.manager_id) WHERE e.manager_id=100 JOIN departments d ON (e.department_id = d.department_id);

Which statement is true regarding the output of this SQL statement? A. The statement would provide the desired results. B. The statement would not execute because the ON clause is written twice. C. The statement would not execute because the WHERE clause is wrongly placed. D. The statement would not execute because the self join uses the ON clause instead of the USING clause.

Q131/140 View the Exhibit and examine the description of the DEPARTMENTS and EMPLOYEES tables. To retrieve data for all the employees for their EMPLOYEE_ID, FIRST_NAME, and DEPARTMENT NAME, the following SQL statement was written: SELECT employee_id, first_name, department_name FROM employees NATURAL JOIN departments; The desired output is not obtained after executing the above SQL statement. What could be the reason for this?

A. The NATURAL JOIN clause is missing the USING clause. B. The table prefix is missing for the column names in the SELECT clause. C. The DEPARTMENTS table is not used before the EMPLOYEES table in the FROM clause. D. The EMPLOYEES and DEPARTMENTS tables have more than one column with the same column name and data type. SELECT employee_id, first_name, department_name FROM employees NATURAL JOIN departments;

Q115/140 Which two statements are true regarding the types of table joins available in Oracle Database? (Choose two.) A. You can use the JOIN clause to join only two tables. B. You can explicitly( 明確的 ) provide the join condition with a NATURAL JOIN. C. You can use the USING clause to join tables on more than one column. D. You can use the ON clause to specify multiple conditions while joining tables.

Q97/140 View the Exhibit and examine the structure of the PRODUCT_INFORMATION and INVENTORIES tables. You have a requirement from the supplies department to give a list containing PRODUCT_ID, SUPPLIER_ID, and QUANTITY_ON_HAND( 庫存量 ) for all the products wherein QUANTITY_ON_HAND is less than five. Which two SQL statements can accomplish the task? (Choose two.) A. SELECT product_id, quantity_on_hand, supplier_id FROM product_information NATURAL JOIN inventories AND quantity_on_hand < 5;

B. SELECT i.product_id, i.quantity_on_hand, i.supplier_id FROM product_information pi JOIN inventories i USING (product_id) AND quantity_on_hand < 5; C. SELECT i.product_id, i.quantity_on_hand, pi.supplier_id FROM product_information pi JOIN inventories i ON (pi.product_id=i.product_id) WHERE quantity_on_hand < 5; D. SELECT i.product_id, i.quantity_on_hand, i.supplier_id FROM product_information pi JOIN inventories i ON (pi.product_id=i.product_id) AND quantity_on_hand < 5;

Q18/140 View the Exhibit and examine the structure for the ORDERS and ORDER_ITEMS tables. You want to display ORDER_ID, PRODUCT_ID, and TOTAL (UNIT_PRICE multiplied by QUANTITY) for all the orders placed in the last seven days. Which query would you execute? A. SELECT order_id, product_id, unit_price*quantity "TOTAL" FROM order_items oi JOIN orders o ON (o.order_id=oi.order_id) WHERE o.order_date>=SYSDATE-7;

B. SELECT o.order_id,oi.product_id, oi.unit_price*oi.quantity "TOTAL" FROM order_items oi JOIN orders o USING (order_id) WHERE o.order_date>=SYSDATE-7; C. SELECT o.order_id, oi.product_id, oi.unit_price*oi.quantity "TOTAL" FROM order_items oi JOIN orders o WHERE o.order_date>=SYSDATE-7 ON (o.order_id=oi.order_id); D. SELECT o.order_id, oi.product_id, oi.unit_price*oi.quantity "TOTAL" FROM order_items oi JOIN orders o ON (o.order_id=oi.order_id) WHERE o.order_date>=SYSDATE-7;