SQL2-ch4 群組相關資料以產生報表. 題號  80 題: 11 、 20 、 43 、 59 、 70 、 80  140 題: 14 、 88 、 113.

Slides:



Advertisements
Similar presentations
WHERE Clause Chapter 2. Objectives Limit rows by using a WHERE clause Use the LIKE operator Effect of NULL values Use compound conditions Use the BETWEEN.
Advertisements

SQL1-ch7 集合運算 1. 題號  80 題: 50 、 55 、 62  140 題: 41 、 61 、
SQL2-ch1 控制使用者存取. 題號  80 題: 14 、 22 、 40 、 42 、 52  140 題: 9 、 40 、 103.
Group functions cannot be used in the WHERE clause: SELECT type_code FROM d_songs WHERE SUM (duration) = 100; (this will give an error)
SQL1-ch2 限制和排序資料. 考古題題號  80 題: 27 、 51  140 題: 23 、 58 、 70.
Set operators (UNION, UNION ALL, MINUS, INTERSECT) [SQL]
Chapter 11 Group Functions
Chapter 11 Group Functions (up to p.402)
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.
18 Copyright © Oracle Corporation, All rights reserved. Advanced Subqueries.
Binary Search (I) Date: June 17, 2009 Introducer: Hsing-Yen Ann.
5 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
Introduction to Java Programming Lecture 5: Using Java Classes : String & Math Spring 2009.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
1 Excel 講授內容 ( 進階 ) 授課教師 : 吳槐桂 最後更新 : 2008/05/01.
資料結構實習-二.
: Where is the Marble? ★☆☆☆☆ 題組: VOLUME CIV 題號: Q Where is the Marble? 解題者:劉淑惠 解題日期: 2006 年 6 月 11 日 題意:有許多上面有號碼的彈珠,將彈珠上面的 號碼由小到大排列,找出某個號碼的第一顆彈珠.
ArcINFO &Geodatabase 由 ESRI 產生 1970 ArcINFO 一開始被設計在迷你電 腦上, 後來逐漸發展, 在 UNIX 系統上也能 執行, 直到今天, 已經可以在不同的平台上 運作.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
Ceng 356-Lab1. Objectives After completing this lesson, you should be able to do the following: Get Familiar with the development environment List the.
Objectives After completing this lesson, you should be able to do the following: Define subqueries Describe the types of problems that the subqueries.
Enhancements to the GROUP BY Clause Fresher Learning Program January, 2012.
Database Programming Sections 5– GROUP BY, HAVING clauses, Rollup & Cube Operations, Grouping Set, Set Operations 11/2/10.
17 Copyright © Oracle Corporation, All rights reserved. Enhancements to the GROUP BY Clause.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
1 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Join, Subqueries and set operators. Obtaining Data from Multiple Tables EMPLOYEES DEPARTMENTS … …
Introduction to SQL PART Ⅰ 第一讲 Writing Basic SQL SELECT Statements.
SQL1-ch8 操作資料 (DML) 1. 題號  80 題: 47 、 67  140 題: 12 、 49 、 50 、 55 、 79 、 80 、 89 、
5 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
5 Copyright © 2004, Oracle. All rights reserved. Displaying Data from Multiple Tables.
Intermediate SQL: Aggregated Data, Joins and Set Operators.
SQL1-ch5 顯示多個表格的資料. 題號  80 題: 34 、 57 、 71 、 72  140 題: 18 、 25 、 62 、 97 、 115 、 131.
SQL1-ch10 其他綱要物件. 題號  80 題: 5 、 9 、 18 、 32 、 38 、 41 、 44 、 54 、 77  140 題: 76 、 78 、 120 、 132.
Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Satrio Agung Wicaksono, S.Kom., M.Kom.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
15 Copyright © Oracle Corporation, All rights reserved. Using SET Operators.
Copyright © 2004, Oracle. All rights reserved. Using the Set Operators.
SQL1-ch1 使用SQL SELECT 敘述句擷取資料.
SQL1-ch3 使用單列函數自訂輸出. 考古題題號  80 題: 7 、 37  140 題: 30 、 43 、 52 、 84 、 86 、 127.
SQL1-ch4 群組函數與聚總資料. 題號  80 題: 33 、 39  140 題: 10 、 59 、 95 、 110.
 After completing this lesson, you should be able to do the following: ◦ Use the ROLLUP operation to produce subtotal values ◦ Use the CUBE operation.
Session 9 Accessing Data from a Database. RDBMS and Data Management/ Session 9/2 of 34 Session Objectives Describe the SELECT statement, its syntax and.
Module 4: Grouping and Summarizing Data. Overview Listing the TOP n Values Using Aggregate Functions GROUP BY Fundamentals Generating Aggregate Values.
05 | SET Operators, Windows Functions, and Grouping Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program.
6 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using Subqueries.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
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 © 2006, Oracle. All rights reserved. Generating Reports by Grouping Related Data.
ORACLE SQL Fundamental II xpp-e-f 重點 xpp-e : Generating Reports by Grouping Related Data xpp-f : Hierarchical Retrieval.
Database Programming Sections 6 –Subqueries, Single Row Subqueries, Multiple-row Subqueries, Correlated Subqueries.
4 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Using Data Model Editor to Create Data Models Based on a SQL Query Data Set.
Writing Basic SQL Statements. Objectives After completing this lesson, you should be able to do the following: –List the capabilities of SQL SELECT statements.
1 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Oracle 10g Retrieving Data Using the SQL SELECT Statement.
1 Copyright © 2009, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
1 Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
6 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using Subqueries.
Retrieving Data Using the SQL SELECT Statement
Oracle Certified 1z0-047 Exam Questions
Using the Set Operators
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
Using CASE Value expression
SQL2-ch3 操控大型資料集.
Using the Set Operators
Presentation transcript:

SQL2-ch4 群組相關資料以產生報表

題號  80 題: 11 、 20 、 43 、 59 、 70 、 80  140 題: 14 、 88 、 113

ROLLUP 與 CUBE  使用 ROLLUP 來產生小計。

ROLLUP 與 CUBE

Q11/80 View the Exhibit and examine the descriptions of ORDER_ITEMS and ORDERS tables. You want to display the CUSTOMER_ID, PRODUCT_ID, and total (UNIT_PRICE multiplied by QUANTITY) for the order placed. You also want to display the subtotals( 小計 ) for a CUSTOMER_ID as well as for a PRODUCT_ID for the last six months. Which SQL statement would you execute to get the desired output?

A. SELECT o.customer_id, oi.product_id, SUM(oi.unit_price*oi.quantity) "Total" FROM order_items oi JOIN orders o ON oi.order_id=o.order_id GROUP BY ROLLUP (o.customer_id,oi.product_id) WHERE MONTHS_BETWEEN(order_date, SYSDATE) <= 6; B. SELECT o.customer_id, oi.product_id, SUM(oi.unit_price*oi.quantity) "Total" FROM order_items oi JOIN orders o ON oi.order_id=o.order_id GROUP BY ROLLUP (o.customer_id,oi.product_id) HAVING MONTHS_BETWEEN(order_date, SYSDATE) <= 6;

C. SELECT o.customer_id, oi.product_id, SUM(oi.unit_price*oi.quantity) "Total" FROM order_items oi JOIN orders o ON oi.order_id=o.order_id GROUP BY ROLLUP (o.customer_id, oi.product_id) WHERE MONTHS_BETWEEN(order_date, SYSDATE) >= 6; D. SELECT o.customer_id, oi.product_id, SUM(oi.unit_price*oi.quantity) "Total" FROM order_items oi JOIN orders o ON oi.order_id=o.order_id WHERE MONTHS_BETWEEN(order_date, SYSDATE) <= 6 GROUP BY ROLLUP (o.customer_id, oi.product_id) ;

Q20/80 In which scenario would you use the ROLLUP operator for expression or columns within a GROUP BY clause? A. to find the groups forming ( 形成 ) the subtotal in a row B. to create group-wise grand totals for the groups specified within a GROUP BY clause C. to create a grouping for expressions or columns specified within a GROUP BY clause in one direction, from right to left for calculating the subtotals D. to create a grouping for expressions or columns specified within a GROUP BY clause in all possible directions, which is cross-tabular report for calculating the subtotals

Q59/80 Which statement is true regarding the ROLLUP operator specified in the GROUP BY clause of a SQL statement? A. It produces only the subtotals for the groups specified in the GROUP BY clause. B. It produces only the grand totals for the groups specified in the GROUP BY clause. C. It produces higher-level subtotals, moving from right to left through the list of grouping columns specified in the GROUP BY clause. D. It produces higher-level subtotals, moving in all the directions through the list of grouping columns specified in the GROUP BY clause.

Q80/80 View the Exhibit and examine a sample of the data existing in the STORES table. You need to generate a report that shows the following details: 1) The total QTY_SOLD of each product in each region of each country. 2) The total QTY_SOLD of all products in each region of each country. 3) The total QTY_SOLD of all products in each country. Which SQL statement gives the required output?

A. SELECT country_id, region, prod_no, SUM(qty_sold) FROM stores GROUP BY CUBE(country_id,region,prod_no); B. SELECT country_id, region, prod_no, SUM(qty_sold) FROM stores GROUP BY ROLLUP(country_id,region,prod_no); C. SELECT country, region, prod_no, SUM(qty_sold) FROM stores GROUP BY GROUPING SETS(country_id,region),prod_no); D. SELECT country, region, prod_no, SUM(qty_sold), GROUPING(country_id) G1, GROUPING(region) G2, GROUPING(prod_no) FROM stores GROUP BY CUBE (country_id,region,prod_no);

GROUPING 函數  與 CUBE 或 ROLLUP 計算子搭配使用  用來找出形成資料列中小計的群組  區別由 ROLLUP 或 CUBE 產生的 NULL 值  傳回 0 或 1

GROUPING 函數

Q43/80 Which statement best describes the GROUPING function? A. It is used to set the order for the groups to be used for calculating the grand totals and subtotals. B. It is used to form various groups to calculate total and subtotals created using ROLLUP and CUBE operators. C. It is used to identify if the NULL value in an expression is a stored NULL value or created by ROLLUP or CUBE. D. It is used to specify the concatenated group expressions to be used for calculating the grand totals and subtotals.

Q70/80 Which two statements are true about the GROUPING function? (Choose two.) A. It is used to find the groups forming( 形成 ) the subtotal in a row. B. It is used to identify the NULL value in the aggregate functions. C. It is used to form the group sets involved in generating the totals and subtotals. D. It can only be used with ROLLUP and CUBE operators specified in the GROUP BY clause.

Q14/140 View the Exhibit and examine the descriptions for ORDERS and ORDER_ITEMS tables. Evaluate the following SQL statement: SELECT o.customer_id, oi.product_id, SUM(oi.unit_price*oi.quantity) "Order Amount" FROM order_items oi JOIN orders o ON oi.order_id = o.order_id GROUP BY CUBE (o.customer_id, oi.product_id); Which three statements are true regarding the output of this SQL statement? (Choose three.)

A. It would return the subtotals for the Order Amount of every CUSTOMER_ID. B. It would return the subtotals for the Order Amount for every PRODUCT_ID. C. It would return the subtotals for the Order Amount of every PRODUCT_ID and CUSTOMER_ID as one group. D. It would return the subtotals for the Order Amount of every CUSTOMER_ID and PRODUCT_ID as one group. E. It would return only the grand( 全部 ) total for the Order Amount of every CUSTOMER_ID and PRODUCT_ID as one group. ON oi.order_id = o.order_id GROUP BY CUBE (o.customer_id, oi.product_id);

Q88/140 Which statement is true regarding the CUBE operator in the GROUP BY clause of a SQL statement? A. It produces only aggregates for the groups specified in the GROUP BY clause. B. It finds all the NULL values in the superaggregates for the groups specified in the GROUP BY clause. C. It produces 2 n possible superaggregate combinations, if the n columns and expressions arespecified in the GROUP BY clause. D. It produces n+1 possible superaggregate combinations, if the n columns and expressions arespecified in the GROUP BY clause.

Q113/140 View the Exhibit and examine the description for EMPLOYEES and DEPARTMENTS tables. Evaluate the following SQL statement: SELECT e.department_id, e.job_id, d.location_id, sum(e.salary) total FROM employees e JOIN departments d ON e.department_id = d.department_id GROUP BY CUBE (e.department_id, e.job_id, d.location_id); Which two statements are true regarding the output of this command? (Choose two.)

A. The output would display the total salary for all the departments. B. The output would display the total salary for all the JOB_IDs in a department. C. The output would display only the grand total of the salary for all JOB_IDs in a LOCATION_ID. D. The output would display the grand total of the salary for only the groups specified in the GROUP BY clause. ON e.department_id = d.department_id GROUP BY CUBE (e.department_id, e.job_id, d.location_id);