MySQL Practice Exercises with Solutions – Part 6
We have split this collection of exercises on MYSQL into seven parts, this is the first one, then you will find the second part, the third part, the fourth part, the fifth part, the sixth part, seventh part, eighth part, and finally the ninth part these exercises are based on simple, advanced and finally complex MYSQL queries. These questions are based on the following two tables, Employee table and Reward table.
Employee table
+-------------+------------+-----------+----------+--------------+-------------+ | Employee_id | First_name | Last_name | Salary | Joining_date | Departement | +-------------+------------+-----------+----------+--------------+-------------+ | 1 | Bob | Kinto | 1000000 | 2019-01-20 | Finance | | 2 | Jerry | Kansxo | 6000000 | 2019-01-15 | IT | | 3 | Philip | Jose | 8900000 | 2019-02-05 | Banking | | 4 | John | Abraham | 2000000 | 2019-02-25 | Insurance | | 5 | Michael | Mathew | 2200000 | 2019-02-28 | Finance | | 6 | Alex | chreketo | 4000000 | 2019-05-10 | IT | | 7 | Yohan | Soso | 1230000 | 2019-06-20 | Banking | +-------------+------------+-----------+----------+--------------+-------------+
Reward table
+-----------------+-------------+--------+ | Employee_ref_id | date_reward | amount | +-----------------+-------------+--------+ | 1 | 2019-05-11 | 1000 | | 2 | 2019-02-15 | 5000 | | 3 | 2019-04-22 | 2000 | | 1 | 2019-06-20 | 8000 | +-----------------+-------------+--------+
Questions
1. Get 20% of Bob’s salary, 10% of Alex’s salary, and 15% of other employees’ salaries.
2. Display the text
- ‘IT services’ instead of ‘IT’,
- ‘Financial services’ instead of ‘Finance’, and
- ‘Banking services’ instead of ‘Banking’
from the “Department” column.
3. Remove employees who have received rewards.
4. Insert employee whose name contains a single quote '
5. Get the name of the employees which contains only numbers.
6. Classify employees according to their reward for one month.
7. Update the reward of “Bob” to 1000.
8. Get the first name, the amount of the reward for the employees who have rewards.
9. Get the first name, the reward amount for employees who have rewards with an amount greater than 2000.
10. Get the first name, the amount of the reward for the employees even if they have not received any rewards.