[SQL][資策會][LAB-1]基本查詢

Lab 3-1基本查詢

1 下列語法能成功執行嗎 ?
 

SELECT last_name, job_id, salary AS Sal
FROM employees;

True/False

ANSWER:      TRUE 可以成功執行

2      下列語法有四個錯誤 您能找出來嗎?
     

SELECT employee_id, last_name
sal x 12 ANNUAL SALARY
FROM employees;

ANSWER:

SELECT employee_id, last_name,
salary * 12 'ANNUAL SALARY'
FROM employees
  1. last name後面的逗號
  2. sal欄位名稱
  3. X乘號
  4. 欄位別名要用  '  asdafg  '  括起來

3  Create a query to display the last name, job code, hire date, and employee number

for each employee, with employee number appearing first. Provide an alias STARTDATE

for the HIRE_DATE column. Save your SQL statement to a file named lab1_3.sql.

 ANSWER:

SELECT employee_id, last_name, job_id, hire_date StartDate
FROM employees

 

4.     Create a query to display unique job codes from the EMPLOYEES table.

 ANSWER:

SELECT DISTINCT job_id
FROM   employees

5.     Display the last name concatenated with the job ID, separated by a comma and space, and name the column Employee and Title.

ANSWER:

SELECT last_name + ', ' + job_id 'Employee and Title'
FROM employees