+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++use employees table which you have imported from employees.csv
file+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++
1. Write a query to display the names (first_name, last_name) using alias name
"First Name", "Last Name".
select first_name,last_name from employees;
2. Write a query to get unique department ID from employee table.
mysql> select distinct department_id from employees;
+---------------+
| department_id |
+---------------+
| 90 |
| 60 |
| 100 |
| 30 |
| 50 |
| 80 |
| 0 |
| 10 |
| 20 |
| 40 |
| 70 |
| 110 |
+---------------+
12 rows in set (0.00 sec)
3. Write a query to get all employee details from the employee table order by first
name, descending.
mysql> select first_name from employees order by first_name desc;
4. Write a query to get the names (first_name, last_name), salary, PF of all the
employees (PF is calculated as 15% of salary).
mysql> select first_name,last_name,salary,pf from employees;
5. Write a query to get the employee ID, names (first_name, last_name), salary in
ascending order of salary.
Select employee_id,first_name,last_name,salary from employees order by salary
desc;
6. Write a query to get the total salaries payable to employees.
select sum(salary) as sum_salary from employees;
+------------+
| sum_salary |
+------------+
| 119282 |
+------------+
1 row in set (0.00 sec)
7. Write a query to get the maximum and minimum salary from employees table.
mysql> select max(salary),min(salary) from employees;
+-------------+-------------+
| max(salary) | min(salary) |
+-------------+-------------+
| 4140 | 362 |
+-------------+-------------+
1 row in set (0.00 sec)
8. Write a query to get the average salary and number of employees in the employees
table.
mysql> select avg(salary),count(employee_id) from employees;
+-------------+--------------------+
| avg(salary) | count(employee_id) |
+-------------+--------------------+
| 1114.7850 | 107 |
+-------------+--------------------+
1 row in set (0.00 sec)
9. Write a query to get the number of employees working with the company.
mysql> select count(*) from employees;
+----------+
| count(*) |
+----------+
| 107 |
+----------+
1 row in set (0.01 sec)
10. Write a query to get the number of jobs available in the employees table.
mysql> select count(*) from employees;
+----------+
| count(*) |
+----------+
| 107 |
+----------+
1 row in set (0.01 sec)
11. Write a query get all first name from employees table in upper case.
12. Write a query to get the first 3 characters of first name from employees table.
select first_name from employees order by first_name limit 3;
+------------+
| first_name |
+------------+
| Adam |
| Alana |
| Alberto |
+------------+
3 rows in set (0.01 sec)
13. Write a query to calculate 171*214+625.
select (171*214)+625;
+---------------+
| (171*214)+625 |
+---------------+
| 37219 |
+---------------+
1 row in set (0.00 sec)
14. Write a query to get the names (for example Ellen Abel, Sundar Ande etc.) of
all the employees from employees table.
15. Write a query to get first name from employees table after removing white
spaces from both side.
16. Write a query to get the length of the employee names (first_name, last_name)
from employees table.
17. Write a query to check if the first_name fields of the employees table contains
numbers.
18. Write a query to select first 10 records from a table.
select * from employees limit 10;
19. Write a query to get monthly salary (round 2 decimal places) of each and every
employee
Note : Assume the salary field provides the 'annual salary' information.
=====================================================================
1. 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.
select first_name,last_name from employees where salary>2000 and salary<4500;
2. Write a query to display the name (first_name, last_name) and department ID of
all employees in departments 30 or 100 in ascending order.
select first_name,last_name,department_id from employees order by department_id
asc limit 70 offset 30;
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.
select first_name,last_name,salary from employees where salary>500 and
salary<4500 limit 70 offset 30;
4. Write a query to display the name (first_name, last_name) and hire date for all
employees who were hired in 1987.
select first_name,last_name,hire_date from employees order by hire_date=1987;
5. Write a query to display the first_name of all employees who have both "b" and
"c" in their first name.
select first_name from employees where first_name like '%b%' and first_name like
'%c%';
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.
select last_name,job_id,salary from employees where job_id
in('it_prog','sh_clerk') and salary !=1500;
7. Write a query to display the last name of employees whose names have exactly 6
characters.
select * from employees where last_name like '______';
8. Write a query to display the last name of employees having 'e' as the third
character.
mysql> select * from employees where last_name like '__e%';
9. Write a query to display the jobs/designations available in the employees table.
select job_id from employees;
10. Write a query to display the name (first_name, last_name), salary and PF (15%
of salary) of all employees.
select first_name,last_name,salary,pf from employees;
11. Write a query to select all record from employees where last name in 'BLAKE',
'SCOTT', 'KING' and 'FORD'.
________select last_name from employees where last_name
in('blake','scott','king','ford');
+-----------+
| last_name |
+-----------+
| King |
| King |
+-----------+
2 rows in set (0.00 sec)
___________________________________________________________________________________
_______________________________________________
1. Write a query to list the number of jobs available in the employees table.
2. Write a query to get the total salaries payable to employees.
3. Write a query to get the minimum salary from employees table.
4. Write a query to get the maximum salary of an employee working as a Programmer.
5. Write a query to get the average salary and number of employees working the
department 90.
6. Write a query to get the highest, lowest, sum, and average salary of all
employees.
7. Write a query to get the number of employees with the same job.
8. Write a query to get the difference between the highest and lowest salaries.
9. Write a query to find the manager ID and the salary of the lowest-paid employee
for that manager.
10. Write a query to get the department ID and the total salary payable in each
department.
11. Write a query to get the average salary for each job ID excluding programmer.
12. Write a query to get the total salary, maximum, minimum, average salary of
employees (job ID wise), for department ID 90 only.
13. Write a query to get the job ID and maximum salary of the employees where
maximum salary is greater than or equal to $4000.
14. Write a query to get the average salary for all departments employing more than
10 employees.