1 / 20

SQL1-ch4

SQL1-ch4. 群組函數與聚總資料. 題號. 80 題: 33 、 39 140 題: 10 、 56 、 95 、 110. 群組函數. 群組函數 (group function) 聚總函數 (aggregate function) 每一組資料列只會有一個結果. 練習. 找出員工資料表中,最資深、資淺員工的聘用日期。. 群組函數. 群組函數與空值. Q39/80( 可略 ). View the Exhibit and examine the description of the PRODUCT_INFORMATION table.

chyna
Download Presentation

SQL1-ch4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SQL1-ch4 群組函數與聚總資料

  2. 題號 • 80題:33、39 • 140題:10、56、95、110

  3. 群組函數 • 群組函數(group function) • 聚總函數(aggregate function) • 每一組資料列只會有一個結果

  4. 練習 • 找出員工資料表中,最資深、資淺員工的聘用日期。

  5. 群組函數 • 群組函數與空值

  6. Q39/80(可略) View the Exhibit and examine the description of the PRODUCT_INFORMATION table. Which SQL statement would retrieve from the table the number of products having LIST_PRICE as NULL?

  7. the number of products having LIST_PRICE as NULL? A. SELECT COUNT(list_price) FROM product_information WHERE list_price IS NULL; B. SELECT COUNT(list_price) FROM product_information WHERE list_price = NULL; C. SELECT COUNT(NVL(list_price, 0)) FROM product_information WHERE list_price IS NULL; D. SELECT COUNT(DISTINCT list_price) FROM product_information WHERE list_price IS NULL;

  8. 資料群組 • 建立資料群組

  9. Q33/80 Evaluate the following SQL statements: Statement 1: SELECT MAX(unit_price*quantity) “Maximum Order” FROM order_items; Statement 2: SELECT MAX(unit_price*quantity) “Maximum Order” FROM order_items GROUP BY order_id; Which statements are true regarding the output of these SQL statements? (Choose all that apply.)

  10. SELECT MAX(unit_price*quantity) “Maximum Order” FROM order_items; SELECT MAX(unit_price*quantity) “Maximum Order” FROM order_items GROUP BY order_id; A. Statement 1 would return only one row of output. B. Both the statements would give the same output. C. Statement 2 would return multiple rows of output. D. Statement 1 would not return any row because the GROUP BY clause is missing. E. Both statements would ignore NULL values for the UNIT_PRICE and QUANTITY columns.

  11. 資料群組 • Group by • 必須放在where子句之後 • 須包含欄位名稱或運算式 • 不可用欄位別名 • 可搭配單列函數使用 • Select子句中沒有使用聚總函數的欄位,須使用Group by分群。

  12. 資料群組 • 依多個欄位分組

  13. 練習 • 找出每個部門中,最資深、資淺員工的聘用日期。

  14. Q110/140 Which two statements are true regarding the GROUP BY clause in a SQL statement? (Choose two.) A. You can use column alias in the GROUP BY clause. B. Using the WHERE clause after the GROUP BY clause excludes the rows after creating groups. C. The GROUP BY clause is mandatory(強制的) if you are using an aggregate function in the SELECT clause. D. Using the WHERE clause before the GROUP BY clause excludes the rows before creating groups. E. If the SELECT clause has an aggregate function, then those individual columns without an aggregate function in the SELECT clause should be included in the GROUP BY clause.(P4-17)

  15. 群組篩選 • 不能在where中使用群組函數

  16. 群組篩選 • 群組條件的篩選,須使用Having子句

  17. Q95/140 Which three statements are true regarding group functions(群組函數)? (Choose three.) A. They can be used on columns or expressions. B. They can be passed as an argument to another group function. C. They can be used only with a SQL statement that has the GROUP BY clause. D. They can be used on only one column in the SELECT clause of a SQL statement. E. They can be used along with the single-row function in the SELECT clause of a SQL statement.(P4-10)

  18. Q10/140 Which three statements are true regarding the WHERE and HAVING clauses in a SQL statement? (Choose three.) A. The HAVING clause conditions can have aggregate functions. B. The HAVING clause conditions can use aliases for the columns. C. WHERE and HAVING clauses cannot be used together in a SQL statement. D. The WHERE clause is used to exclude rows before the grouping of data. E. The HAVING clause is used to exclude one or more aggregated results after grouping data.

  19. Q59/140(可略) View the Exhibit and examine the description of the PRODUCT_INFORMATION table. Which SQL statement would retrieve from the table the number of products having LIST_PRICE as NULL? A. SELECT COUNT(list_price) FROM product_information WHERE list_price IS NULL; B. SELECT COUNT(list_price) FROM product_information WHERE list_price = NULL;

  20. C. SELECT COUNT(NVL(list_price, 0)) FROM product_information WHERE list_price IS NULL; D. SELECT COUNT(DISTINCT list_price) FROM product_information WHERE list_price IS NULL;

More Related