SQL Assignments
SQL Assignments
SQL Assignments
ename varchar(10),
job varchar(10),
hiredate date,
sal number(4,0));
desc EMP;
DNAME VARCHAR(10),
LOC VARCHAR(10));
desc DEPT;
DNAME VARCHAR(10),
LOC VARCHAR(10));
desc DEPT;
desc EMP;
Name varchar(20),
City varchar(15),
Pincode number(8),
State varchar(15),
BalDue number(10,2));
desc CLIENT_MASTER;
desc DEPT;
desc PROJECT;
Name varchar(20),
City varchar(15),
BalDue number(10,2));
City VARCHAR(15),
desc Student;
select EMPNO, ENAME, JOB from EMP where JOB in ('SALESMAN', 'MANAGER', 'ANALYST');
select EMPNO, ENAME, JOB from EMP where JOB = 'SALESMAN' and EMPNO > 7500;
select EMPNO, ENAME from EMP where ENAME LIKE 'M%' or ENAME LIKE '%N';
select EMPNO, ENAME from EMP where ENAME LIKE '%A%' and JOB = 'SALESMAN';
alter table EMP add constraint FK_EDNO FOREIGN KEY(EDNO) references DEPT(DEPTNO);
PNO number(2),
WEEK_HRS number(2));
Cname varchar(30),
Percentage number(3),
Floor number(2),
HOD varchar(20));
desc COURSE;
Co_ID NUMBER(3),
desc Faculty;
City VARCHAR(30),
CID NUMBER(3),
Class_coordinator NUMBER(3),
desc STUDENTS;
select ename as employee_name, LPAD('Rs ' || TO_CHAR(SAL), 6, ' ') as padded_salary from EMP;
select ename as employee_name, RPAD(TO_CHAR(SAL) || ' $', 5, ' ') as padded_salary from EMP;
select ename as employee_name, CASE WHEN job = 'ANALYST' THEN 'PROGRAMMER' ELSE job END as
modified_job from EMP;
select ename as employee_name, '(' || TO_CHAR(SAL, '$999,999.00') || ')' as forma ed_salary from
EMP;
select SYSDATE from DUAL;
select TO_CHAR(SYSDATE, 'FMDAY, DDth MONTH, YYYY') as forma ed_date from DUAL;
select TO_CHAR(HIREDATE, 'FMDAY, DDth MONTH, YYYY') as forma ed_hire_date from EMP;
select EMPNO, ENAME, HIREDATE, EXTRACT(YEAR FROM HIREDATE) as hire_year from EMP;
create table STUDENT3(
SECTION varchar(20),
QUOTA varchar(5));
desc STUDENT3;
select JOB, MAX(SAL) as MAX_SALARY, MIN(SAL) as MIN_SALARY from EMP GROUP BY JOB;
select DEPTNO, MAX(SAL) as MAX_SALARY, MIN(SAL) as MIN_SALARY from EMP GROUP BY DEPTNO;
select DEPTNO, AVG(SAL) as AVERAGE_SALARY from EMP GROUP BY DEPTNO HAVING COUNT(EMPNO)
> 4;
select EMP.* from EMP JOIN DEPT on EMP.DEPTNO = DEPT.DEPTNO where DEPT.DNAME = 'SALES';
select EMP.* from EMP JOIN WORK_FOR on EMP.EMPNO = WORK_FOR.ENO where WORK_FOR.PNO in
(10, 20);
select COUNT(*) as num_employees from EMP where EMP.EMPNO in (select WORK_FOR.ENO from
WORK_FOR JOIN PROJECT on WORK_FOR.PNO = PROJECT.PNO where PROJECT.PTYPE =
'ELECTRONICS');
select EMP.EMPNO,
EMP.ENAME,
SUM(WORK_FOR.WEEK_HRS) as TOTAL_HOURS_WORKED
from EMP
select EMP.ENAME,
DEPT.DNAME
from EMP
select EMP.ENAME,
DEPT.DNAME,
DEPT.LOC
from EMP
select EMP.ENAME,
EMP.JOB,
DEPT.DNAME,
DEPT.LOC
from EMP
select EMP.ENAME,
EMP.JOB,
DEPT.DNAME,
DEPT.LOC
from EMP
from EMP
select EMP.ENAME,
EMP.JOB,
MAX(EMP.SAL) AS MAX_SALARY
from EMP
select EMP.ENAME,
EMP.JOB,
PROJECT.PNAME
from EMP
from DEPT
select DEPT.DNAME
from DEPT
select ENAME
from EMP
select * from EMP where SAL > (select SAL from EMP where ENAME = 'JONES');
select * from EMP where JOB = (select JOB from EMP where ENAME = 'SMITH');
select E.*
from EMP E
where E.DEPTNO = 20
and E.JOB IN (
from EMP E2
where SAL IN (
select SAL
from EMP
and SAL > (select SAL from EMP where ENAME = 'MARTIN');
select * from EMP where SAL > (select SUM(SAL) from EMP where JOB = 'SALESMAN');
where E.HIREDATE > (select HIREDATE from EMP where ENAME = 'BLAKE')
select E.* from EMP E where E.SAL = (select MAX(SAL) from EMP
where DEPTNO = (select DEPTNO from DEPT where DNAME = 'RESEARCH'));
where DEPTNO = 10
and JOB NOT IN (select DISTINCT JOB from EMP where DEPTNO = 20);