LAB 1 Exercises
LAB 1 Exercises
1. Display the last name concatenated with the job ID, separated by a comma and space, and name the
column Employee and Title.
SELECT last_name || ', ' || job_id AS "Employee and Title" FROM hr.employees;
2. Create a query to display all the data from the EMPLOYEES table. Separate each column by a
comma. Name the column THE_OUTPUT.
SELECT employee_id || ', ' || first_name || ', ' || last_name || ', ' ||
email || ', ' || phone_number || ', ' || hire_date || ', ' ||
job_id || ', ' || salary || ', ' || commission_pct || ', ' || manager_id || ', ' || department_id AS
THE_OUTPUT FROM hr.employees;
Dania Noor(CT-23010)
3. Show the structure of the DEPARTMENTS table. Select all data from the table.
DESC hr.departments;
4. Show the structure of the EMPLOYEES table. Create a query to display the last name, job code,
hire date, and employee number for each employee, with employee number appearing first.
DESC hr.employees;
Dania Noor(CT-23010)
5. Create a query to display unique job codes from the EMPLOYEES table.
SELECT DISTINCT job_id FROM hr.employees;
Dania Noor(CT-23010)
6. There are four coding errors in this statement. Can you identify them? SELECT employee_id,
last_name sal x 12 ANNUAL SALARY FROM employees;
Corrected:
SELECT employee_id, last_name AS sal, salary * 12 AS "ANNUAL SALARY" FROM employees;
7. Make account on leetcode, head to https://leetcode.com/studyplan/top-sql-50/ and solve 5 questions
in the select tag. The questions involve usage of “Where” clause.
1. select product_id from Products where low_fats = 'Y' and recyclable = 'Y'
3. select name, population, area from World where area >= 3000000 or population >= 25000000
4. select distinct author_id as id from Views where author_id = viewer_id order by author_id