MySQL Restricting and Sorting Data - Exercises, Practice, Solution
MySQL Restricting and Sorting Data - Exercises, Practice, Solution
3. Write a query to display the name (first_name, last_name) and salary for all
employees whose salary is not in the range $10,000 through $15,000 and are in
department 30 or 100.
4. Write a query to display the name (first_name, last_name) and hire date for all
employees who were hired in 1987.
5. Write a query to display the first_name of all employees who have both "b" and
"c" in their first name.
6. Write a query to display the last name, job, and salary for all employees whose
job is that of a Programmer or a Shipping Clerk, and whose salary is not equal to
$4,500, $10,000, or $15,000.
7. Write a query to display the last name of employees whose names have
exactly 6 characters.
8. Write a query to display the last name of employees having 'e' as the third
character.
11. Write a query to select all record from employees where last name in
'BLAKE', 'SCOTT', 'KING' and 'FORD'.
Page | 3
ACCENTURE BATCH 2 LABORATORY
Write a query to display the names (first_name, last_name) and salary for all
Page | 4 employees whose salary is not in the range $10,000 through $15,000.
FROM employees
Copy
Page | 5
ACCENTURE BATCH 2 LABORATORY
Code:
SELECT first_name, last_name, department_id
FROM employees
Copy
Page | 7
ACCENTURE BATCH 2 LABORATORY
Page | 8
ACCENTURE BATCH 2 LABORATORY
Code:
SELECT first_name, last_name, salary, department_id
FROM employees
Copy
Page | 10
ACCENTURE BATCH 2 LABORATORY
Write a query to display the name (first_name, last_name) and hire date for all
Page | 11 employees who were hired in 1987.
Code:
SELECT first_name, last_name, hire_date
FROM employees
Copy
ACCENTURE BATCH 2 LABORATORY
Page | 12
ACCENTURE BATCH 2 LABORATORY
Write a query to display the first_name of all employees who have both "b" and
Page | 13 "c" in their first name.
Code:
SELECT first_name
FROM employees
Copy
Page | 14
ACCENTURE BATCH 2 LABORATORY
Write a query to display the last name, job, and salary for all employees whose
Page | 15 job is that of a Programmer or a Shipping Clerk, and salary is not equal to
$4,500, $10,000, or $15,000.
Code:
SELECT last_name, job_id, salary
FROM employees
Copy
Page | 16
ACCENTURE BATCH 2 LABORATORY
Write a query to display the last name of employees whose name have exactly 6
Page | 17 characters.
Code:
SELECT last_name FROM employees WHERE last_name LIKE '______';
Copy
Page | 18
ACCENTURE BATCH 2 LABORATORY
Write a query to display the last name of employees having 'e' as the third
Page | 19 character.
Code:
SELECT last_name FROM employees WHERE last_name LIKE '__e%';
Copy
Page | 20
ACCENTURE BATCH 2 LABORATORY
Code:
SELECT DISTINCT job_id FROM employees;
Copy
Page | 22
ACCENTURE BATCH 2 LABORATORY
Write a query to display the name (first_name, last_name), salary and PF (15%
Page | 23 of salary) of all employees.
Code:
SELECT first_name, last_name, salary, salary*.15 PF from employees;
Copy
ACCENTURE BATCH 2 LABORATORY
Page | 24
ACCENTURE BATCH 2 LABORATORY
Write a query to select all records from employees where last name in 'JONES',
Page | 25 'BLAKE', 'SCOTT', 'KING' and 'FORD'.
Code:
SELECT *
FROM employees
Copy
Page | 26