1 / 15

SQL1-ch1

SQL1-ch1. 使用 SQL SELECT 敘述句擷取資料. 考古題題號. 80 題: 8 、 25 140 題: 104 、 123. SELECT 敘述. Select :從資料庫中擷取資訊 選取 所有 欄位資料 選取 特定 欄位資料. SELECT 敘述. SQL 敘述句不區分大小寫。 SQL 敘述句可以是單行或多行。 關鍵字不得以縮寫表示,也不能跨行斷字。 使用分號 (;) 來結束每一個 SQL 敘述句。. SELECT 敘述. 可使用四則運算 ( 先乘除後加減 ) 空值 (null) :無法使用、指定的值 ( 空值與 0 和空格不同 ).

Télécharger la présentation

SQL1-ch1

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-ch1 使用SQL SELECT 敘述句擷取資料

  2. 考古題題號 • 80題:8、25 • 140題:104、123

  3. SELECT敘述 • Select:從資料庫中擷取資訊 • 選取所有欄位資料 • 選取特定欄位資料

  4. SELECT敘述 • SQL 敘述句不區分大小寫。 • SQL 敘述句可以是單行或多行。 • 關鍵字不得以縮寫表示,也不能跨行斷字。 • 使用分號(;) 來結束每一個SQL敘述句。

  5. SELECT敘述 • 可使用四則運算(先乘除後加減) • 空值(null):無法使用、指定的值(空值與0和空格不同)

  6. Q8/80 Your company decided to give a monthly bonus of $50 to all the employees who have completed five years in the company. The following statement is written to display the LAST_NAME, DEPARTMENT_ID, and the total annual salary: SELECT last_name, department_id, salary+50*12 "Annual Compensation" FROM employees WHERE MONTHS_BETWEEN(SYSDATE, hire_date)/12 >= 5; When you execute the statement, the "Annual Compensation" is not computed correctly. What changes would you make to the query to calculate the annual compensation correctly?

  7. Q8 資料選擇(SQL1 ch1) SELECT last_name, department_id, salary+50*12 "Annual Compensation" FROM employees WHERE MONTHS_BETWEEN(SYSDATE, hire_date)/12 >= 5; A. Change the SELECT clause to SELECT last_name, department_id, salary*12+50 "Annual Compensation". B. Change the SELECT clause to SELECT last_name, department_id, salary+(50*12) "Annual Compensation". C. Change the SELECT clause to SELECT last_name, department_id, (salary+50)*12 "Annual Compensation". D. Change the SELECT clause to SELECT last_name, department_id, (salary*12)+50 "Annual Compensation".

  8. SELECT敘述 • 重覆資料列(Distinct) • 練習:顯示員工(employees)表格的所有工作代碼(job_id)

  9. SELECT敘述 • 欄位名可以使用別名 • 可用AS或是空白 • 別名中若有空白字元,前後要加 “”

  10. SELECT敘述 • 連結欄位符號(||) • 連結字串(‘’單引號) • 若字串中有「單引號」,使用q運算子。

  11. Q104/140 Evaluate the following SQL statement: SELECT product_name || 'it's not available for order' FROM product_information WHERE product_status = 'obsolete'; You received the following error while executing the above query: ERROR: ORA-01756: quoted string not properly terminated What would you do to execute the query successfully?

  12. A. Enclose the character literal string in the SELECT clause within the double quotation marks. B. Do not enclose the character literal string in the SELECT clause within the single quotation marks. C. Use Quote (q) operator and delimiter to allow the use of single quotation mark in the literal character string. D. Use escape character to negate the single quotation mark inside the literal character string in the SELECT clause.

  13. Q25/80(可略) Your company wants to give 5% bonus to all the employees on their annual salary. The SALARY column stores the monthly salary for an employee. To check the total for annual salary and bonus amount for each employee, you issued the following SQL statement: SELECT first_name, salary, salary*12+salary*12*.05 “ANNUAL SALARY + BONUS” FROM employees; Which statement is true regarding the above query?

  14. A. It would execute and give you the desired output. B. It would not execute because the AS keyword is missing between the column name and the alias. C. It would not execute because double quotation marks are used instead of single quotation marks for assigning alias for the third column. D. It would execute but the result for the third column would be inaccurate because the parentheses for overriding the precedence of the operator are missing.

  15. Q123/140(可略) View the Exhibit and examine the description of the PRODUCT_INFORMATION table. You want to display the expiration date of the warranty for a product as on today. Which SQL statement would you execute? A. SELECT product_id, SYSDATE + warranty_period FROM product_information; B. SELECT product_id, TO_YMINTERVAL(warranty_period) FROM product_information; C. SELECT product_id, TO_YMINTERVAL(SYSDATE) + warranty_period FROM product_information; D. SELECT product_id, TO_YMINTERVAL(SYSDATE + warranty_period) FROM product_information;

More Related