You are on page 1of 5

2.

2)
1) select dept_code,round(max(staff_sal)) as "Maximum",round(min(staff_sal)) as
"Minimum",round(sum(staff_sal)) as "Total",round(avg(staff
_sal)) as "Average" from staff_master group by dept_code;

DEPT_CODE Maximum Minimum Total Average


---------- ---------- ---------- ---------- ----------
30 42000 17000 91000 30333
20 62000 20000 124000 31000
40 18000 18000 18000 18000
10 32000 24000 56000 28000

2) select dept_code,count(mgr_code) as "Total_Number_Of_Managers" from staff_master


group by dept_code;

DEPT_CODE Total_Number_Of_Managers
---------- ------------------------
30 3
20 4
40 1
10 2

3) select deptno,sum(sal) from emp where job not like '%MANAGER%' group by deptno
having sum(sal)>6500;

DEPTNO SUM(SAL)
---------- ----------
30 6550
20 7900

SQL> select dept_code,sum(staff_sal) from staff_master where mgr_code not


in(100006,100007) group by dept_code;

DEPT_CODE SUM(STAFF_SAL)
---------- --------------
30 42000
20 62000

___________________________________________________________________________________
___________________________
___________________________________________________________________________________
___________________________

2.1)

1) select staff_name,to_char(staff_sal,'$9999999.9999999999') from staff_master;

STAFF_NAME TO_CHAR(STAFF_SAL,'$
-------------------------------------------------- --------------------
Arvind $17000.0000000000
Shyam $20000.0000000000
Mohan $24000.0000000000
Anil $20000.0000000000
John $32000.0000000000
Allen $42000.0000000000
Smith $62000.0000000000
Raviraj $18000.0000000000
Rahul $22000.0000000000
Ram $32000.0000000000

10 rows selected.

___________________________________________________________________________________
___________________________________________________

2) SELECT student_name,to_char(student_dob,'MONTH DD YYYY') from student_master


where trim(to_char(student_dob,'DAY')) In('SATURDAY'
,'SUNDAY');

STUDENT_NAME
TO_CHAR(STUDENT_DOB,'MONTHDDYYYY')
--------------------------------------------------
--------------------------------------------
Ravi NOVEMBER 01 1981
Raj JANUARY 14 1979
Arvind JANUARY 15 1983
Mehul JANUARY 17 1982
Vijay JANUARY 19 1980
Rajat JANUARY 20 1980
Ramesh DECEMBER 27 1980
Amit Raj SEPTEMBER 28 1980

8 rows selected.

___________________________________________________________________________________
_______________________________

3)

SQL> SELECT staff_name,round(months_between(sysdate,hiredate)) as "Months Worked"


from staff_master;

STAFF_NAME Months Worked


-------------------------------------------------- -------------
Arvind 195
Shyam 206
Mohan 206
Anil 217
John 218
Allen 215
Smith 205
Raviraj 195
Rahul 184
Ram 207

___________________________________________________________________________________
_____________

4)
SQL> select staff_name,staff_sal,rpad(' ',staff_sal/1000 + 1,'X') from
staff_master;
___________________________________________________________________________________
_______________________________________

5)
SQL> select * from staff_master where to_number(to_char(hiredate,'DD'))<=15 AND
to_char(hiredate,'MON')='DEC';

STAFF_CODE STAFF_NAME DESIGN_CODE


DEPT_CODE STAFF_DOB HIREDATE MGR_CODE STAFF_SAL STAFF_AD
DRESS
---------- -------------------------------------------------- -----------
---------- --------- --------- ---------- ---------- --------
-----------------------------------------------------------------------------------
----------------------------------------------------
-----------------------------------------------------------------------------------
--------------
100009 Rahul 102
20 16-JAN-78 11-DEC-03 100006 22000 Hyderaba

___________________________________________________________________________________
___________________________________________________________________________________
________

6) select staff_name,staff_sal,case when staff_sal>=50000 then 'A' when


staff_sal>=25000 and staff_sal<50000 then 'B' when staff_sal>=10000 and
staff_sal<25000 the
n 'C' else 'D' end as "Grade" from staff_master;

STAFF_NAME STAFF_SAL G
-------------------------------------------------- ---------- -
Arvind 17000 C
Shyam 20000 C
Mohan 24000 C
Anil 20000 C
John 32000 B
Allen 42000 B
Smith 62000 A
Raviraj 18000 C
Rahul 22000 C
Ram 32000 B

___________________________________________________________________________________
__________________________________________

7) select staff_name,to_char(hiredate,'DY') as "Day" from staff_master order by


mod(to_char(hiredate, 'D') + 5, 7);

STAFF_NAME Day
-------------------------------------------------- ------------
Allen MON
Smith TUE
Arvind WED
Rahul THU
Ram THU
Raviraj SAT
Mohan SAT
Anil SUN
Shyam SUN
John SUN

10 rows selected.

___________________________________________________________________________________
_____________________________________________________

8) select rpad(substr(staff_name,0,1),length(staff_name)-1,'*')||
substr(staff_name,length(staff_name),length(staff_name)) from staff_master;

____----------
A****d
S***m
M***n
A**l
J**n
A***n
S***h
R*****j
R***l
R*m

___________________________________________________________________________________
_________________________________________________________

9) select instr('mississippi','i',1,3) from dual;

INSTR('MISSISSIPPI','I',1,3)
----------------------------
8

___________________________________________________________________________________
_______

10)
SQL> select to_char(next_day(last_day(sysdate)- interval '7'
day,'Friday'),'FMDDSPTH "Of
" MONTH YYYY') as "Pay Date",to_char(next_day(last_day(sysdate),'Friday'),'DAY')
from emp
;

Pay Date
TO_CHAR(NEXT_DAY(LAST_DAY(SYS
DATE),'
-----------------------------------------------------------
-----------------------------
-------
TWENTY-SIXTH Of APRIL 2019 FRIDAY
TWENTY-SIXTH Of APRIL 2019 FRIDAY
TWENTY-SIXTH Of APRIL 2019 FRIDAY
TWENTY-SIXTH Of APRIL 2019 FRIDAY
TWENTY-SIXTH Of APRIL 2019 FRIDAY
TWENTY-SIXTH Of APRIL 2019 FRIDAY
TWENTY-SIXTH Of APRIL 2019 FRIDAY
TWENTY-SIXTH Of APRIL 2019 FRIDAY
TWENTY-SIXTH Of APRIL 2019 FRIDAY
TWENTY-SIXTH Of APRIL 2019 FRIDAY
TWENTY-SIXTH Of APRIL 2019 FRIDAY
Pay Date
TO_CHAR(NEXT_DAY(LAST_DAY(SYS
DATE),'
-----------------------------------------------------------
-----------------------------
-------
TWENTY-SIXTH Of APRIL 2019 FRIDAY
TWENTY-SIXTH Of APRIL 2019 FRIDAY
TWENTY-SIXTH Of APRIL 2019 FRIDAY

14 rows selected.

___________________________________________________________________________________
_______________________________________________________________

11) select
student_code,student_name,decode(dept_code,20,'Electricals',30,'Electronics','Other
s') as "Department Name" from student_master;

STUDENT_CODE STUDENT_NAME Department


------------ -------------------------------------------------- -----------
1001 Amit Others
1002 Ravi Others
1003 Ajay Electricals
1004 Raj Electronics
1005 Arvind Others
1006 Rahul Others
1007 Mehul Electricals
1008 Dev Others

You might also like