DBMS Assignments
DBMS Assignments
ASSTGNMEN
ORDER BY "Day";
FROM emp
ORDER BY "Day";
<br>
NUMBERS
TO_char functions with the
7) Display the sal, comm From emp for all the recordes below format
Eg: james sal is 0,950.00 and comm is 0.000.00 and totsal 0.950.00
10) Display the below o/p for all the recordes using
runtime weekday and use the aliae
11) Display the below o/p for all the recordes
TO NUMBER FUNCTIONS
converts a
string to a DATE
The Oracle/PLSQL TO DATE function
<br>
ASSTGNMENT5
JOINS
PArT-4
1. Suppose there is annual salary information provided by emp table. How to fetch monthly
salary of each and every employee?
2. Select allrecord from emp table where deptno=30 and sal>1500
3. Select all record from emp table where deptno =10 or 40.
.
4. In emp table add comm+sal as total sal Select any salary <3000 from emp table.
5. Select all record from emp where ename in 'BLAKE,"SCOTT,' KINGand'FORD'
15. display the year in four digit format deptno from dept table,dname&and
sum of salary
and group by above select columns and order by year.
more than 2
16. from the above query op display the information ofemployees who joined
employees in that particular.
18. fetch the recordes ename.job,deptno,dname,loc using table alias &fetch those recordes
job should match with MANAGER AND ANALYST
20.fetch the recordes of employee and their managers using table alias the column should
manager column nume should be
be employee column should be ename and their
ename
<br>
21) SELECT
Employees.Ename "Employees",
Managers.Ename "Managers"
FROM Emp Employees, Emp Managers
WHERE Employees.Mgr = Managers.Empno
23) fetch the ename sal deptno dname loc using left outer join
24) fetch the ename sal deptno dname loc using right outer join
29) SELECT
E.name Employee,
E.Deptno Department,
M.Ename Manager,
M.Deptno "Manager's Dept" FROM
Emp E, Dept D, Emp M WHERE
E.MGR = M.Empno AND
E.Deptno=D.Deptno;
30) SELECT
E.Ename Employee, Dname Department,
Loc Place,
M.Ename Manager,
Dname "Manager's Dept" E.MGR
FROM Emp E, Dept D, Emp M WHERE
= M.Empno AND
E.Deptno = D.Deptno;
<br>
36) SELECT
E.Êname Employee,
M.Ename Manager
FROM
Emp E INNER JOIN Emp M
ONE.MGR=M.Empno)
<br>
ASSIGNMENT
-5
PART-)
1) Writea query to supply the alias to table and retricve the data from emp, dent.
2) Write a query use * to relerences display tlhe allthe enp details from dept 10 & along all the
columns rom emp using table alias.
SET OPERATOR
3) Display ename, deptno using sct opcrator ordered by cname using sub-qucry.
4) Display ename from cmp and dname from dept using interscct operator from dept 10,30.
S) Display ename from cmp and dname from dept using minus operator from dept 10,30.
6) Display the job from emp,dept using union allopcrator from dept 10,30.
7) Display the job which is common in all 3 dept using union or intcrscct opcrator.
8)Display the job which is common in all3 dept using union opcrator and runtime values.
9) Display the total salary of cach group along with total salary & group by deptno.
<br>
1)Write a query using equijoin ename, empno, job, dname, loc from
emp,dept.
2) Write a query using equijoin ename, empno, job, dname, loc from emp,dept using USING
clause
3) Write a query using equijoinename, empno, job,dname, loc from emp,dept using ON clause.
NON-EQUIJOIN
3) Select ename, empno, loc from emp who are working in dept 10, 20.
SELF JOIN
1)Select empno,ename,job,deptno from emp using selfjoin.
4SsTGNMENT-6
ASSIGNMENT IV GROUP BY CLAUSE),HAVING CLAUSE),AGGREGATE FUNTIOONS
Group by clause:
Aggregate functions are normally used in conjunction with a GROUP BY clause. The GROUP
BY clause enables you to use aggregate functions to answer more
complex managerial questions
such as:
Group by function establishes data groups based on columns and aggregates the
information
within a group only. The grouping criterion is defined by the columns specified in GROUP BY
clause. Following this hierarchy, data is first organized in the groups and then WHERE clause
restricts the rows in each group.
() Allthe dependent columns or columns used in GROUP BY function must form the basis of
grouping, hence must be included in GROUP BY clause also.
FROM employees;
DEPARTMENT ID,
(2) GROUP BY clause does not support the use of column alias, but the actual names.
(3) GROUP BY clause can only be used with aggregate functions like SUM, AVG, COUNT,
MAX, and MIN.If it is used with single row functions,
Oracle will return the "ORA-00934: group function not allowed" here error message.
FROM employees
department. Note
Similarly, below query to find sum of salarics for respective job ids cach
in
appcar in GROUP BY
the group is establishedbascd on Department and Job id. So they
clause.
FROM employees
on the
The below query also produces the same result. Please note that grouping is based
department id and job id columns but not used for display purpose.
FROM employees
3) Display the departments tot salary using aggregate function&group by exclude dept 10.
Year
1981
1982
1983
5. Display the below o/p using TO CHAR & GROUP BY & ORDERBY
Year
April
December
February
Select deptno from emp note: assending descending exit with orderby clase
Group by deptno
Order by desc
FROM EMP
SELECT
TO CHAR(HIREDATE,'MONTH') MONTH,
FROM EMP
GROUP BY
TO CHAR(HIREDATE,'MM')
TO CHAR(HIREDATE,'MONTH')
FROM EMP
GROUPBY DEPTNO
FROM EMP:
Select
To_char(hiredate,'yyyy') year,
Deptnojob,sum(sal)
From emp
Group by
Deptno,
Job,
To char(hiredate,'yyyy')
15.Display the year, halfyear, quarter, month, week, deptnum, job, sum(sal)
using group by
clause.
Aggregate Functions
Aggregate functions perform a variety of actions such as counting all the rows in a table,
averaging a column's data, and summing numeric data.
1. Count the number of employees in the emp table.
2. Write the query returns the average of the salaries of employees in the organization using
alias.
3. Write the query returns the sum of thesalaries of employees in theorganization.using alias
4. SELECT query returns the oldest and latest hired dates
of employees in the organization.
<br>
SQL> SELECT
AVG (SALARY)
FROM EMPLOYEE:
SQL> SELECT
JOB \D.
SUM (SALARY)
FROM EMPLOYEE
GROUPBY JOB ID
SELECT
JOB ID,
MAX(SALARY)
FROM EMPLOYEE
GROUPBY JOB ID
SELECT
DEPARTMENT ID,
MIN(HIRE DATE)
FROM EMPLOYEE
GROUP BY DEPARTMENT_ID
SQL> SELECT
DEPARTMENT ID,
COUNT ()
FROM EMPLOYEE
GROUP BY DEPARTMENT ID
SQL> SELECT
COUNT(EMPLOYEE ID)
FROM EMPLOYEE
WHERE SAL > 5000
<br>
Multiple single-row functions can be nested together. but group functions can be nested up to
two levels only. The nested function call COUNT(SUM(AVG(
X)))
Returns the error, "ORA-00935: group function is nested too deeply." Hovwever, using
nested
single-row functions within group functions works fine
SELECT
SUM(AVG(LENGTH(LAST NAME))
FROM EMPLOYEES
GROUP BY DEPARTMENT ID
GROUP BY ename;
GROUP BY functions work with actual values of the column only i.e. ignoring
the NULL values
(COUNT(*) is exception here). But this feature creates major difference in terms calculations,
of
end analytic results.
But to avoid their ignoring, handling of NULL values in the columns is necessary
because
ignoring of NULL values might produce incorrect results
Select
Avg(comm)
From emp
Select
Avg(nvl(comm.,0)
From emp
<br>
A WHERE clause is used to filter rows BEFORE the GROUPING action (i.e., before the
calculation of the aggregate functions).
A HAVING clause filters rows AFTER the GROUPING action (i.e., after the calculation of the
aggregate functions).
A HAVING clause filters rows AFTER the GROUPING action (i.e., after the calculation of the
aggregate functions).
FROM employees
GROUP BY JOB ID
The HAVING clause is a conditional option that is directly related to the GROUP BY clause
option because a HAVING clause eliminates rows from a result table based on the result of a
GROUPBY clause.
FROM employees
SSI GNMENT
SUBQUERIES
9)list the department names which are having more than 5 employees
12)Display all the employee names in research and sales department who are having at least
1