Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Multi Row Functions (Questions From Google)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

MULTI ROW FUNCTIONS (QUESTIONS FROM GOOGLE)

MAX, MIN, COUNT, SUM, AVG

1. Write a query to fetch the EmpFname from the Emp table in upper case and use the ALIAS name
as Empname?
select LOWER(Ename) as Empname
from emp;

ANS:
EMPNAME
----------
smith
allen
ward
jones
martin
blake
clark
scott
king
turner
adams
james
ford
miller

2. Write a query to select maximum salary from employees table.


Select max(sal)
From emp;
ANS: MAX(SAL)
---------
5000

3. Write a query to select second maximum salary from employee’s table.


SELECT max(sal)
FROM Employees
WHERE sal NOT IN (SELECT max(salary) FROM Employees);
ANS: MAX(SAL)
---------
3000
4. Display average salary in the department 30.
select avg(sal)
from emp
where deptno=30;
ANS: AVG(SAL)
----------
1566.66667

5. Display number of employees working in department 10 and 30.


select count(*)
from emp
where deptno in( '10','30');
ANS: 9

6. Display all the employee id and its maximum salary.


Select emp no, max(sal)
from emp
group by emp no
order by 1;
ANS:

FUNCTIONS
Multi row functions SQL queries
1. WAQTD minimum salary in employee’s table

select min(sal)
from emp;

ANS: MIN(SAL)

----------

800

2. WAQTD total salary given to all the employees

select sum(sal)
from emp;

ANS: SUM(SAL)
----------

29025

3. WAQTD average salary given to all the employees

select avg(sal)
from emp;

ANS: AVG(SAL)

----------

2073.21429

4. WAQTD max salary given in department 10

select max(sal)
from emp
where deptno=10;

ANS: MAX(SAL)

----------

5000

5. WAQTD number of employees in employee’s table

select count(*)
from emp;

ANS: COUNT(*)

----------

14

6. WAQTD number of employees getting salary less than 2000 in department 10

select count(*)
from emp
where sal<2000 and deptno = 10;

ANS: COUNT(*)

----------

1
7. WAQTD total salary needed to pay the employees working as clerk

select sum(sal)
from emp
where job in 'CLERK';

ANS: SUM(SAL)

----------

4150

8. WAQTD number of employees having A as their first character

select count(*)
from emp
where ename like ‘A%’;

ANS: COUNT(*)

----------

9. WAQTD number of employees working as clerk or manager


select count(*)
from emp
where job in (‘CLERK’,’MANAGER’);

ANS: COUNT(*)

----------

10. WAQTD total salary needed to pay employees hired in the month of Feb

select sum(sal)
from emp
where hiredate like '%FEB%';

ANS: SUM(SAL)

----------
2850
11. WAQTD number of employees reporting to 7839(MGR)

select count(*)
from emp
where MGR in 7839;

Ans: COUNT(*)

----------

12. WAQTD number of employees getting commission in deptno 30

select count(*)
from emp
where comm is not null and deptno in 30;

ANS: COUNT(*)

----------

13. WAQTD average salary, total salary, number of employees and maximum salary given to the
employees working as president

select avg(sal), sum(sal), count(*), max(sal)


from emp
where ename ='PRESIDENT';

ANS: AVG(SAL) SUM(SAL) COUNT(*) MAX(SAL)

---------- ---------- ---------- ----------

14. WAQTD number of employees having 'A' letter in their name


select count(*)
from emp
where ename like '%A%';

ANS: COUNT(*)

----------

7
15. WAQTD number of employees and total salary needed to pay the employees who have 2
consecutive L's in their name
select count(*)
from emp
where ename like '%LL%';

ANS: COUNT(*)

----------

16. WAQTD number of departments present in employee table

select count (distinct deptno)


from emp;

ANS: COUNT(DISTINCTDEPTNO)

---------------------

GROUP BY FUNCTIONS
WAQTD maximum sal in each department

select max(sal), deptno

from emp

group by deptno;

MAX(SAL) DEPTNO

---------- ----------

2850 30

3000 20

5000 10

WAQTD number of employees in each department if employees are earning >2000

select count(*), deptno

from emp

where sal>2000

group by deptno;
COUNT(*) DEPTNO

---------- ----------

1 30

3 20

2 10

Q: WAQTD Avg sal of employees in each job

select avg(sal), job

from emp

group by job;

AVG(SAL) JOB

---------- ---------

1037.5 CLERK

1400 SALESMAN

5000 PRESIDENT

2758.33333 MANAGER

3000 ANALYST

ASSIGNMENT:

1. WAQTD NUMBER OF EMPLOYEES WORKING IN EACH DEPARTMENT EXCEPT PRESIDENT

2. WAQTD TOTAL SALARY NEEDED TO PAY ALL THE EMPLOYEES IN EACH JOB
3. WAQTD NUMBER OF EMPLOYEES WORKING AS MANAGER IN EACH DEPARTMENT

4. WAQTD AVG SALARY NEEDED TO PAY ALL THE EMPLOYEES IN EACH DEPARTMENT EXCLUDING THE
EMPLOYEES OF DEPTNO 20

5. WAQTD NUMBER OF EMPLOYEES HAVING CHARACTER 'A' IN THEIR NAMES IN EACH JOB

6. WAQTD NUMBER OF EMPLOYEES AND AVG SALARY NEEDED TO PAY THE EMPLOYEES WHO’S
SALARY IS GREATER THAN 2000 IN EACH DEPARTMENT
7. WAQDTD NUMBER OF EMPLOYEES AND SALARY GIVEN TO ALL THE SALESMAN IN EACH DEPT

8. WAQTD NUMBER OF EMPLOYEES WITH THEIR MAXIMUM SALARIES IN EACH JOB

9. WAQTD MAXIMUM SALARIES GIVEN TO AN EMPLOYEE WORKING IN EACH DEPT

10. WAQTD NUMBER OF TIMES THE SALARIES ARE PRESENT IN EMPLOYEE TABLE

11. WAQTD NUMBER OF EMPLOYEES HIRED ON THE SAME DAY INTO THE SAME DEPARTMENT
12. WAQTD NUMBER OF EMPLOYEES GETTING THE SAME SALARY IN THE SAME DEPARTMENT

13. WAQTD NUMBER OF EMPLOYEES WORKING IN EACH DEPARTMENT HAVING ATLEAST 2 EMP'S IN
EACH DEPT

You might also like