CBSE Class 12 Computer Science
Question 79 of 91
Grouping Records, Joins in SQL — Question 14
Back to all questions 14
Question With reference to the table below, answer the questions that follow :
Table : Employees
| Empid | Firstname | Lastname | Address | City |
|---|---|---|---|---|
| 010 | Ravi | Kumar | Raj nagar | GZB |
| 105 | Harry | Waltor | Gandhi nagar | GZB |
| 152 | Sam | Tones | 33 Elm St. | Paris |
| 215 | Sarah | Ackerman | 440 U.S. 110 | Upton |
| 244 | Manila | Sengupta | 24 Friends street | New Delhi |
| 300 | Robert | Samuel | 9 Fifth Cross | Washington |
| 335 | Ritu | Tondon | Shastri Nagar | GZB |
| 400 | Rachel | Lee | 121 Harrison St. | New York |
| 441 | Peter | Thompson | 11 Red Road | Paris |
Table : EmpSalary
| Empid | Salary | Benefits | Designation |
|---|---|---|---|
| 010 | 75000 | 15000 | Manager |
| 105 | 65000 | 15000 | Manager |
| 152 | 80000 | 25000 | Director |
| 215 | 75000 | 12500 | Manager |
| 244 | 50000 | 12000 | Clerk |
| 300 | 45000 | 10000 | Clerk |
| 335 | 40000 | 10000 | Clerk |
| 400 | 32000 | 7500 | Salesman |
| 441 | 28000 | 7500 | Salesman |
Write the SQL commands for the following using above tables :
(i) To show firstname, lastname, address and city of all employees living in Pairs.
(ii) To display the content of Employees table in descending order of Firstname.
(iii) To display the firstname, lastname and total salary of all managers from the tables Employes and EmpSalary, where total salary is calculated as Salary + Benefits.
(iv) To display the maximum salary among managers and clerks from the table EmpSalary.
(i)
SELECT Firstname, Lastname, Address, City
FROM Employees
WHERE City = 'Paris';+-----------+----------+-------------+-------+
| Firstname | Lastname | Address | City |
+-----------+----------+-------------+-------+
| SAM | TONES | 33 ELM ST. | PARIS |
| PETER | THOMPSON | 11 RED ROAD | PARIS |
+-----------+----------+-------------+-------+
(ii)
SELECT *
FROM Employees
ORDER BY Firstname DESC;+-------+-----------+----------+-------------------+------------+
| empid | FIRSTNAME | LASTNAME | ADDRESS | CITY |
+-------+-----------+----------+-------------------+------------+
| 215 | SARAH | ACKERMAN | 440 U.S. 110 | UPTON |
| 152 | SAM | TONES | 33 ELM ST. | PARIS |
| 300 | ROBERT | SAMUEL | 9 FIFTH CROSS | WASHINGTON |
| 335 | RITU | TONDON | SHASTRI NAGAR | GZB |
| 10 | RAVI | KUMAR | RAJ NAGAR | GZB |
| 400 | RACHEL | LEE | 121 HARRISON ST. | NEW YORK |
| 441 | PETER | THOMPSON | 11 RED ROAD | PARIS |
| 244 | MANILA | SENGUPTA | 24 FRIENDS STREET | NEW DELHI |
| 105 | HARRY | WALTOR | GANDHI NAGAR | GZB |
+-------+-----------+----------+-------------------+------------+
(iii)
SELECT e.Firstname, e.Lastname,
(s.Salary + s.Benefits) AS TotalSalary
FROM Employees e, EmpSalary s
WHERE e.Empid = s.Empid AND s.Designation = 'Manager';+-----------+----------+-------------+
| Firstname | Lastname | TotalSalary |
+-----------+----------+-------------+
| RAVI | KUMAR | 90000 |
| HARRY | WALTOR | 80000 |
| SARAH | ACKERMAN | 87500 |
+-----------+----------+-------------+
(iv)
SELECT Designation, MAX(Salary)
FROM EmpSalary
WHERE Designation IN ('Manager', 'Clerk')
group by designation;+-------------+-------------+
| Designation | MAX(Salary) |
+-------------+-------------+
| MANAGER | 75000 |
| CLERK | 50000 |
+-------------+-------------+