You are on page 1of 1

W3schools data

for practice
CREATE TABLE "DEPT"(
"DEPTNO" NUMBER NOT NULL PRIMARY KEY,
"DNAME" VARCHAR2(255),
"LOC" VARCHAR2(255)
);
CREATE TABLE "EMP"(
"EMPNO" NUMBER NOT NULL PRIMARY KEY,
"ENAME" VARCHAR2(255),
"JOB" VARCHAR2(255),
"MGR" NUMBER REFERENCES EMP("EMPNO"),
"HIREDATE" DATE,
"SALARY" NUMBER,
"COMM" NUMBER,
"DEPTNO" NUMBER REFERENCES DEPT("DEPTNO")
);

delete emp;
delete dept;
INSERT ALL
INTO DEPT VALUES(10,'ACCOUNTING','NEW YORK')
INTO DEPT VALUES(20,'RESEARCH','INDIA')
INTO DEPT VALUES(30,'SALES','CHINA')
INTO DEPT VALUES(40,'OPERATIONS','THAILAND')
SELECT * FROM DUAL;
INSERT ALL
INTO EMP VALUES(7839,'SHUBHAM','PRESIDENT',NULL,'17-NOV-1981',5000,0,10)
INTO EMP VALUES(7369,'SIMMY','CLERK',7902,'17-DEC-1980',800,0,20)
INTO EMP VALUES(7499,'ISHIKA','SALESMAN',7698,'20-FEB-1981',1600,300,30)
INTO EMP VALUES(7521,'SHIV','SALESMAN',7698,'22-FEB-1981',1250,500,30)
INTO EMP VALUES(7566,'RAVI','MANAGER',7839,'02-APR-1981',2975,0,20)
INTO EMP VALUES(7654,'ANKIT','SALESMAN',7698,'28-SEP-1981',1250,1400,30)
INTO EMP VALUES(7698,'VAISHALI','MANAGER',7839,'01-MAY-1981',2850,0,30)
INTO EMP VALUES(7782,'URVASHI','MANAGER',7839,'09-JUN-1981',2450,0,10)
INTO EMP VALUES(7788,'ASRA','ANALYST',7566,'19-DEC-1982',3000,0,20)
INTO EMP VALUES(7844,'DIVYA','SALESMAN',7698,'08-SEP-1981',1500,0,30)
INTO EMP VALUES(7876,'TRIPATHI','CLERK',7788,'12-JAN-1983',1100,0,20)
INTO EMP VALUES(7900,'UDDESH','CLERK',7698,'03-DEC-1981',950,0,30)
INTO EMP VALUES(7902,'AAYUSH','ANALYST',7566,'03-DEC-1981',3000,0,20)
INTO EMP VALUES(7934,'ANCHAL','CLERK',7782,'23-DEC-1982',1300,0,10)
SELECT * FROM DUAL;
INSERT INTO EMP VALUES(7839,'SHUBHAM','PRESIDENT',NULL,'17-NOV-1981',5000,0,10);
INSERT INTO EMP VALUES(7698,'VAISHALI','MANAGER',7839,'01-MAY-1981',2850,0,30);
INSERT INTO EMP VALUES(7782,'URVASHI','MANAGER',7839,'09-JUN-1981',2450,0,10);
INSERT INTO EMP VALUES(7566,'RAVI','MANAGER',7839,'02-APR-1981',2975,0,20);
INSERT INTO EMP VALUES(7499,'ISHIKA','SALESMAN',7698,'20-FEB-1981',1600,300,30);
INSERT INTO EMP VALUES(7521,'SHIV','SALESMAN',7698,'22-FEB-1981',1250,500,30);

SELECT JOB FROM EMP WHERE DEPTNO = 10 MINUS (SELECT JOB FROM EMP WHERE DEPTNO =
20);
SELECT * FROM DEPT WHERE DEPTNO IN(SELECT DEPTNO FROM EMP WHERE COUNT(EMPNO) > 2
GROUP BY DEPTNO);
select count(empno),dname from emp,DEPT where emp.deptno = dept.deptno group by
dname,job having count(empno) >= 2;
SELECT COUNT(EMPNO) ,DNAME FROM EMP JOIN DEPT ON EMP.DEPTNO = DEPT.DEPTNO GROUP BY
DNAME HAVING COUNT(EMPNO) >=2;