0% found this document useful (0 votes)
48 views

MySQL Query

The document provides SQL queries to retrieve employee and department information from database tables. Some queries return basic employee details, salaries and department IDs. Other queries find specific employee names and salaries that meet certain conditions like working in a particular department, earning above or below certain amounts.

Uploaded by

Hamesh Gavali
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

MySQL Query

The document provides SQL queries to retrieve employee and department information from database tables. Some queries return basic employee details, salaries and department IDs. Other queries find specific employee names and salaries that meet certain conditions like working in a particular department, earning above or below certain amounts.

Uploaded by

Hamesh Gavali
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

MySQL

1)  Write a query to display the names (first_name, last_name) using alias


name “First Name", "Last Name"
2) Write a query to get unique department ID from employee table
3)  Write a query to get all employee details from the employee table order by
first name, descending.
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).
5) Write a query to list the number of jobs available in the employees table.
6) Write a query to get the department ID and the total salary payable in each
department.
7) Write a query to get the total salary, maximum, minimum, average salary
of employees (job ID wise), for department ID 90 only. 
8) Write a query to get the average salary and number of employees working
the department 90. 
9) Write a query to find the name (first_name, last_name) of all employees
who works in the IT department.
10) Write a query to find the name (first_name, last_name) of the
employees who are managers.
11)  Write a query to find the name (first_name, last_name), and salary
of the employees who earns more than the average salary and works in
any of the IT departments. 
12) Write a query to find the name (first_name, last_name), and salary of
the employees who earn the same salary as the minimum salary for all
departments. 
13) Write a query to find the name (first_name, last_name) and salary of
the employees who earn a salary that is higher than the salary of all the
Shipping Clerk (JOB_ID = 'SH_CLERK'). Sort the results of the salary of
the lowest to highest.
14)  Write a query to find the name (first_name, last_name) of the
employees who are not supervisors.
15) Write a query to fetch even numbered records from employees table.
+-------------+-------------+-------------+----------+--------------------+------------+------------+----------+----------------
+------------+---------------+
| EMPLOYEE_ID | FIRST_NAME | LAST_NAME | EMAIL | PHONE_NUMBER | HIRE_DATE |
JOB_ID | SALARY | COMMISSION_PCT | MANAGER_ID | DEPARTMENT_ID |
+-------------+-------------+-------------+----------+--------------------+------------+------------+----------+----------------
+------------+---------------+
| 100 | Steven | King | SKING | 515.123.4567 | 1987-06-17 | AD_PRES | 24000.00 | 0.00
| 0| 90 |
| 101 | Neena | Kochhar | NKOCHHAR | 515.123.4568 | 1987-06-18 | AD_VP | 17000.00 |
0.00 | 100 | 90 |
| 102 | Lex | De Haan | LDEHAAN | 515.123.4569 | 1987-06-19 | AD_VP | 17000.00 |
0.00 | 100 | 90 |
| 103 | Alexander | Hunold | AHUNOLD | 590.423.4567 | 1987-06-20 | IT_PROG | 9000.00 |
0.00 | 102 | 60 |
| 104 | Bruce | Ernst | BERNST | 590.423.4568 | 1987-06-21 | IT_PROG | 6000.00 | 0.00
| 103 | 60 |
| 105 | David | Austin | DAUSTIN | 590.423.4569 | 1987-06-22 | IT_PROG | 4800.00 |
0.00 | 103 | 60 |
| 106 | Valli | Pataballa | VPATABAL | 590.423.4560 | 1987-06-23 | IT_PROG | 4800.00 |
0.00 | 103 | 60 |
| 107 | Diana | Lorentz | DLORENTZ | 590.423.5567 | 1987-06-24 | IT_PROG | 4200.00 |
0.00 | 103 | 60 |
| 108 | Nancy | Greenberg | NGREENBE | 515.124.4569 | 1987-06-25 | FI_MGR | 12000.00 |
0.00 | 101 | 100 |
| 109 | Daniel | Faviet | DFAVIET | 515.124.4169 | 1987-06-26 | FI_ACCOUNT | 9000.00 |
0.00 | 108 | 100 |
| 110 | John | Chen | JCHEN | 515.124.4269 | 1987-06-27 | FI_ACCOUNT | 8200.00 |
0.00 | 108 | 100 |
| 111 | Ismael | Sciarra | ISCIARRA | 515.124.4369 | 1987-06-28 | FI_ACCOUNT | 7700.00 |
0.00 | 108 | 100 |
| 112 | Jose Manuel | Urman | JMURMAN | 515.124.4469 | 1987-06-29 | FI_ACCOUNT | 7800.00 |
0.00 | 108 | 100 |
| 113 | Luis | Popp | LPOPP | 515.124.4567 | 1987-06-30 | FI_ACCOUNT | 6900.00 |
0.00 | 108 | 100 |
| 114 | Den | Raphaely | DRAPHEAL | 515.127.4561 | 1987-07-01 | PU_MAN | 11000.00 |
0.00 | 100 | 30 |
| 115 | Alexander | Khoo | AKHOO | 515.127.4562 | 1987-07-02 | PU_CLERK | 3100.00 |
0.00 | 114 | 30 |
| 116 | Shelli | Baida | SBAIDA | 515.127.4563 | 1987-07-03 | PU_CLERK | 2900.00 |
0.00 | 114 | 30 |
| 117 | Sigal | Tobias | STOBIAS | 515.127.4564 | 1987-07-04 | PU_CLERK | 2800.00 |
0.00 | 114 | 30 |

Sample Table – Employee


+-------------+-------------+-------------+----------+--------------------+------------+------------+----------+----------------+------------+---------------+
| EMPLOYEE_ID | FIRST_NAME | LAST_NAME | EMAIL | PHONE_NUMBER | HIRE_DATE | JOB_ID | SALARY | COMMISSION
+-------------+-------------+-------------+----------+--------------------+------------+------------+----------+----------------+------------+---------------+
| 100 | Steven | King | SKING | 515.123.4567 | 1987-06-17 | AD_PRES | 24000.00 | 0.00 | 0| 90 |
| 101 | Neena | Kochhar | NKOCHHAR | 515.123.4568 | 1987-06-18 | AD_VP | 17000.00 | 0.00 | 100 | 90 |
| 102 | Lex | De Haan | LDEHAAN | 515.123.4569 | 1987-06-19 | AD_VP | 17000.00 | 0.00 | 100 | 90 |
| 103 | Alexander | Hunold | AHUNOLD | 590.423.4567 | 1987-06-20 | IT_PROG | 9000.00 | 0.00 | 102 | 60 |
| 104 | Bruce | Ernst | BERNST | 590.423.4568 | 1987-06-21 | IT_PROG | 6000.00 | 0.00 | 103 | 60 |
| 105 | David | Austin | DAUSTIN | 590.423.4569 | 1987-06-22 | IT_PROG | 4800.00 | 0.00 | 103 | 60 |
| 106 | Valli | Pataballa | VPATABAL | 590.423.4560 | 1987-06-23 | IT_PROG | 4800.00 | 0.00 | 103 | 60 |

Sample Tbale- Department

+---------------+----------------------+------------+-------------+
| DEPARTMENT_ID | DEPARTMENT_NAME | MANAGER_ID | LOCATION_ID |
+---------------+----------------------+------------+-------------+
| 10 | Administration | 200 | 1700 |
| 20 | Marketing | 201 | 1800 |
| 30 | Purchasing | 114 | 1700 |
| 40 | Human Resources | 203 | 2400 |
| 50 | Shipping | 121 | 1500 |
| 60 | IT | 103 | 1400 |
| 70 | Public Relations | 204 | 2700 |

You might also like