Excellent Consultancy Pvt. Ltd. maintains two tables for all its employees.
Table : Employee
| Employee_id | First_name | Last_name | Salary | Joining_date | Department |
|---|---|---|---|---|---|
| E101 | Monika | Das | 100000 | 2019-01-20 | Finance |
| E102 | Mehek | Verma | 600000 | 2019-01-15 | IT |
| E103 | Manan | Pant | 890000 | 2019-02-05 | Banking |
| E104 | Shivam | Agarwal | 200000 | 2019-02-25 | Insurance |
| E105 | Alisha | Singh | 220000 | 2019-02-28 | Finance |
| E106 | Poonam | Sharma | 400000 | 2019-05-10 | IT |
| E107 | Anshuman | Mishra | 123000 | 2019-06-20 | Banking |
Table : Reward
| Employee_id | Date_reward | Amount |
|---|---|---|
| E101 | 2019-05-11 | 1000 |
| E102 | 2019-02-15 | 5000 |
| E103 | 2019-04-22 | 2000 |
| E106 | 2019-06-20 | 8000 |
Write suitable SQL queries to perform the following task : (i) Change the Department of Shivam to IT in the table Employee. (ii) Remove the record of Alisha from the table Employee. (iii) Add a new column Experience of integer type in the table Employee. (iv) Display the first name, last name and amount of reward for all employees from the tables Employee and Reward. (v) Display first name and salary of all the employees whose amount is less than 2000 from the tables Employee and Reward. OR Write suitable SQL queries for the following task : (i) Display the year of joining of all the employees from the table Employee. (ii) Display each department name and its corresponding average salary. (iii) Display the first name and date of reward of those employees who joined on Monday from the tables Employee and Reward. (iv) Display sum of salary of those employees whose reward amount is greater than 3000 from the tables Employee and Reward. (v) Remove the table Reward.
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Part (a): UPDATE, DELETE, ALTER ADD, LEFT JOIN, and filtered INNER JOIN. Part (b): YEAR(), GROUP BY AVG, Monday-join (0 rows), SUM(Salary) where Amount>3000 = 1000000, DROP TABLE.
Part (a)
(i) Modify one row with UPDATE, identifying Shivam:
UPDATE Employee SET Department='IT' WHERE First_name='Shivam';
(ii) Remove a row with DELETE:
DELETE FROM Employee WHERE First_name='Alisha';
(iii) Add a new integer column with ALTER TABLE:
ALTER TABLE Employee ADD Experience INT;
(iv) "For all employees" means every employee must appear even without a reward, so use a LEFT JOIN on Employee_id; missing rewards show NULL.
(v) "Whose amount is less than 2000" needs a reward, so an INNER JOIN with WHERE Amount<2000. From the data only E101 (Monika, reward 1000) qualifies; E103's reward is exactly 2000, which is not less than 2000.
UPDATE Employee SET Department='IT' WHERE First_name='Shivam';
DELETE FROM Employee WHERE First_name='Alisha';
ALTER TABLE Employee ADD Experience INT;
SELECT E.First_name, E.Last_name, R.Amount
FROM Employee E LEFT JOIN Reward R ON E.Employee_id=R.Employee_id;
SELECT E.First_name, E.Salary
FROM Employee E INNER JOIN Reward R ON E.Employee_id=R.Employee_id
WHERE R.Amount < 2000; …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.