The relation scheme given below is used to store information about the employees of a company, where empId is the key and deptId indicates the department to which the employee is assigned. Each employee is assigned to exactly one department. emp(empId, name, gender, salary, deptId) Consider the following SQL query: select deptId, count(⋆) from emp where gender = "female" and salary > (select avg(salary) from emp) group by deptId; The above query gives, for each department in the company, the number of female employees whose salary is greater than the average salary of

The relation scheme given below is used to store information about the employees of a company, where empId is the key and deptId indicates the department to which the employee is assigned. Each employee is assigned to exactly one department. emp(empId, name, gender, salary, deptId) Consider the following SQL query: select deptId, count(⋆) from emp where gender = "female" and salary > (select avg(salary) from emp) group by deptId; The above query gives, for each department in the company, the number of female employees whose salary is greater than the average salary of Correct Answer employees in the company.

Answer: Option 3

Explanation:

 (select avg(salary) from emp)

This part of the Query will get evaluated first and gives " Average Salary of all employees in the company."

select deptId, count(⋆)

from emp

where gender = "female" and salary > (select avg(salary) from emp)

group by deptId;

this will count for each department no of employees who are female and whose salary is greater than the average salary.

Lets take an example 

Empid

Name

Gender

Salary

deptid

1

A

Male

2000

CSE

2

B

Female

3000

CSE

3

C

Male

4000

CSE

4

D

Female

5000

CSE

5

E

Male

3000

ME

6

F

Female

4000

ME

7

G

Male

4000

ME

8

H

Female

2000

ME

9

I

Male

1000

CE

10

J

Female

2000

CE

11

K

Male

4000

CE

12

L

Female

5000

CE

13

M

Male

3000

EC

14

N

Female

4000

EC

15

O

Female

5000

EC

 

(select avg(salary) from emp) this will return 3400 as the average salary.

and final Query result will be

Deptid

count

CSE

1

ME

1

CE

1

EC

2

Related Questions

Consider the following relational schema: employee(empId,empName,empDept) customer(custId,custName,salesRepId,rating) salesRepId is a foreign key referring to empId of the employee relation. Assume that each employee makes a sale to at least one customer. What does the following query return? SELECT empName FROM employee E WHERE NOT EXISTS (SELECT custId FROM customer C WHERE C.salesRepId = E.empId AND C.rating <> ’GOOD’);
The given question is followed by two statements numbered I and II. The question may or may not be answered with the help of these statements. You have to decide if these statements are sufficient to answer the question. The four employees of a company have monthly salaries that total Rs. 30,000. What is the salary of the highest paid of these employees ? Statements: I. The highest paid employee has a monthly salary that is twice as great as that of each of the other three employees. Il. The highest paid employee has a monthly salary that is exactly Rs. 6000 greater than that of each of the other 3 employees.