Multi Row Functions (Questions From Google)
Multi Row Functions (Questions From Google)
Multi Row Functions (Questions From Google)
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
FUNCTIONS
Multi row functions SQL queries
1. WAQTD minimum salary in employee’s table
select min(sal)
from emp;
ANS: MIN(SAL)
----------
800
select sum(sal)
from emp;
ANS: SUM(SAL)
----------
29025
select avg(sal)
from emp;
ANS: AVG(SAL)
----------
2073.21429
select max(sal)
from emp
where deptno=10;
ANS: MAX(SAL)
----------
5000
select count(*)
from emp;
ANS: COUNT(*)
----------
14
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
select count(*)
from emp
where ename like ‘A%’;
ANS: COUNT(*)
----------
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(*)
----------
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
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(*)
----------
ANS: COUNT(DISTINCTDEPTNO)
---------------------
GROUP BY FUNCTIONS
WAQTD maximum sal in each department
from emp
group by deptno;
MAX(SAL) DEPTNO
---------- ----------
2850 30
3000 20
5000 10
from emp
where sal>2000
group by deptno;
COUNT(*) DEPTNO
---------- ----------
1 30
3 20
2 10
from emp
group by job;
AVG(SAL) JOB
---------- ---------
1037.5 CLERK
1400 SALESMAN
5000 PRESIDENT
2758.33333 MANAGER
3000 ANALYST
ASSIGNMENT:
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
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