KnowledgeBoat Logo

Computer Science

With reference to the table below, answer the questions that follow :

Table : Employees

EmpidFirstnameLastnameAddressCity
010RaviKumarRaj nagarGZB
105HarryWaltorGandhi nagarGZB
152SamTones33 Elm St.Paris
215SarahAckerman440 U.S. 110Upton
244ManilaSengupta24 Friends streetNew Delhi
300RobertSamuel9 Fifth CrossWashington
335RituTondonShastri NagarGZB
400RachelLee121 Harrison St.New York
441PeterThompson11 Red RoadParis

Table : EmpSalary

EmpidSalaryBenefitsDesignation
0107500015000Manager
1056500015000Manager
1528000025000Director
2157500012500Manager
2445000012000Clerk
3004500010000Clerk
3354000010000Clerk
400320007500Salesman
441280007500Salesman

Give the Output of following SQL commands :

(i) Select firstname, Salary from Employees, Empsalary where Designation = 'Salesman' and Employees.Empid = Empsalary.Empid ;

(ii) Select count(distinct designation) from EmpSalary ;

(iii) Select designation, sum(salary) from EmpSalary group by designation having count(*) > 2 ;

(iv) Select sum(Benefits) from EmpSalary where Designation = 'Clerk' ;

SQL Joins & Grouping

5 Likes

Answer

(i)

Output
+-----------+--------+
| FIRSTNAME | SALARY |
+-----------+--------+
| RACHEL    |  32000 |
| PETER     |  28000 |
+-----------+--------+

(ii)

Output
+-----------------------------+
| COUNT(DISTINCT DESIGNATION) |
+-----------------------------+
|                           4 |
+-----------------------------+

(iii)

Output
+-------------+-------------+
| DESIGNATION | SUM(SALARY) |
+-------------+-------------+
| MANAGER     |      215000 |
| CLERK       |      135000 |
+-------------+-------------+

(iv)

Output
+---------------+
| SUM(BENEFITS) |
+---------------+
|         32000 |
+---------------+

Answered By

1 Like


Related Questions