Sunteți pe pagina 1din 4

STD XI EMPNO 7369 7499 7521 7566 7654 7698 7782 7788 7839 7844 7876 7900 7902

2 7934 ENAME SMITH ALLEN WARD JONES MARTIN BLAKE CLARK SCOTT KING TURNER ADAMS JAMES FORD MILLER

KENDRIYA VIDYALAYA GOPALPUR MILITARY STATION PRACTICAL COPY SUB: INFORMATICS PRACTICES JOB CLERK SALESMAN SALESMAN MANAGER SALESMAN MANAGER MANAGER ANALYST PRESIDENT SALESMAN CLERK CLERK ANALYST CLERK MGR 7902 7698 7698 7839 7698 7839 7839 7566 7698 7788 7698 7566 7782 Table: EMP HIREDATE 17-Dec-80 20-Feb-81 22-Feb-81 2-Apr-81 28-Sep-81 1-May-81 9-Jun-81 19-Apr-87 17-Nov-81 8-Sep-81 23-May-87 3-Dec-81 3-Dec-81 23-Jan-82 SAL 800 1600 1250 2975 1250 2850 2450 3000 5000 1500 1100 950 3000 1300 COMM 300 500 1400 DEPTNO 20 30 30 20 30 30 10 20 10 30 20 30 20 10

Table: DETAILS DEPTNO DNAME LOC 10 MKT MUMBAI 20 FIN DELHI 30 PDT PUNE SELECT WHERE i) To display the records of all employees who work as SALESMAN in DEPTNO 20 ii) To display the records of all employees with names of five characters and working in DEPTNO 10 iii) To display the records of all employees working as CLERK and getting SALARY between 1000 and 1200 iv) To display the records of all employees not working in DEPTNO 10 and 20 and joined before 01-01-1980 v) To display the records of all employees who are not SALESMAN and get a salary less than 2500 vi) To display the records of all employees who working from 01-01-1980 and do not get a commission PATTERN i) To Display the records of all employees whose names start with S. ii) To Display the records of all employees whose JOB have the letters NAG in them. iii) To Display the records of all employees whose names have E as their second last character. NOT i) To display the Records of all employees who do not receive any commission. ii) To display the Records of all employees who do not work in DEPTNO 10 iii) To display the Records of all employees who do not get alary in between 800 to 1200 SELECT ROWS i) To display the ENAME, JOB and MGR CODE of all the employees sorted in descending order of SALARY. ii) To display the EMPLOYEE NO, SALARY and HIREDATE of all the employees sorted in ascending order of DEPTNO iii) To display the ENAME, JOB and COMM of all the employees sorted in ascending order of HIREDATE SELECT DISTINCT i) To display the unique types of JOB done by the employees. ii) To display the unique types of DEPTNO of employees. NULL i) To display the details of the employee who does not have a manager ii) To display the list all employees who get a commission iii) To display the list all employees who do not get a commission > < BETWEEN i) To display the record of all employees who have salary in the range of 800 to 1500 ii) To display the record of all employees who joined in the period between 01-01-1980 to 01-01-1981 iii) To display the record of all employees who have commission from 0 to 200. LIST i) To display the record of all employees who have jobs as SALESMAN, MANAGER and ANALYST ii) To display the record of all employees who work in department no 10,20,30 iii) To display the record of all employees who salaries as 800,1000 and 1200 SELECT WITH CONCAT i) To display the ENAME, JOB and SALARY of all employees in the following format. SMITH HAS JOB CLERK WITH SALARY 800 ALLEN HAS JOB SALESMAN WITH SALARY 1600

ii) To display the ENAME, DEPTNO and SAL of all employees in the following format. SMITH WORKS IN 20 WITH 800 ALLEN WORKS IN 30 WITH 1600 AGGREGATE FUNCTIONS i) Find the max SALARY of all employees ii) Find the min Salary in deptno 10 iii) Find the sum of all Salary for all employees in deptno 10 and 20 iv) Find the average of Salary of Department 10 and 20 v) Find the number of employees in Deptno 10 and 20 CREATE i) Create the table EMPNEW with datatypes and constraint as provided COLUMN NAME DATA TYPE LENGTH CONSTRAINT EMPNO Integer 5 PRIMARY KEY ENAME Character 20 NOT NULL JOB Character 20 MGR Integer 3 NOT NULL HIREDATE Date SAL Float 7,2 Should not be less than zero COMM Integer 4 Default value is NULL DEPTNO Integer 2 References DETAILS (DEPTNO) TO BE CARRIED OUT ON TABLE EMPNEW INSERT i) Write the commands to insert the first two records in the table EMP UPDATE i) Change the Department of FORD to 10 ii) Increase the SALARY of all Employees by 5 % iii) Input the COMM of BLAKE 10% of SALARY DELETE i) Delete the record of BLAKE ii) Delete the record of all employees who are in Deptno 10 ALTER i) Add a new column Phone char(10) to the table EMP ii) Increase the column size of ENAME by 10 iii) Add NOT NULL Constraint to Phone column DROP i) Drop the table EMPNEW GROUP BY i) Show the number of employees in each Department ii) Show the average Salary of the employees in department 10 and 20 iii) Show the min HIREDATE of each Deptno where minimum HIREDATE is greater than 22-Feb-1998 JOIN i) To display the ENAME, DEPTNO AND DNAME of all employees ii) To display the ENAME, DNAME and LOC of all employees who are in DNAME FIN iii) To display the ENAME, HIREDATE and LOC of all employees of DNAME MKT SCALER EXPRESSIONS i) To display the ENAME, SALARY, COMM, SALARY + COMM AS TOTAL of all employees in the following format. ENAME SAL COMM TOTAL ( SALARY + COMM) SMITH 800 800 ALLEN 1600 300 1600 WARD 1250 500 1250 JONES 2975 2975 ii) To display the ENAME, JOB, MIDDLE (4 characters starting from 3rd Position of JOB) of all employees in the following format. ENAME JOB MIDDLE SMITH CLERK ERK ALLEN SALESMAN LESM

WARD JONES

SALESMAN MANAGER

LESM NAGE

NB: *Write the String, Numeric and Date_Time Functions available with MYSQL ANSWERS SELECT WHERE SELECT * FROM EMP WHERE JOB=SALESMAN AND DEPTNO=20; SELECT * FROM EMP WHERE ENAME LIKE _ _ _ _ _ AND DEPTNO =10; SELECT * FROM EMP WHERE JOB=CLERK AND SAL BETWEEN 1000 AND 1200; SELECT * FROM EMP WHERE DEPTNO NOT IN (10,20) AND HIREDATE<1980-01-01; SELECT * FROM EMP WHERE NOT JOB=SALESMAN AND SAL<=2500; SELECT * FROM EMP WHERE HIREDATE>=1980-01-01 AND COMM IS NULL; PATTERN SELECT * FROM EMP WHERE ENAME LIKE S%; SELECT * FROM EMP WHERE JOB LIKE %NAG%; SELECT * FROM EMP WHERE ENAME LIKE %E_; NOT SELECT * FROM EMP WHERE COMM IS NULL; SELECT * FROM EMP WHERE NOT DEPTNO = 10; SELECT * FROM EMP WHERE NOT SAL BETWEEN 800 AND 1200; SELECT ROWS SELECT ENAME, JOB AND MGR FROM EMP ORDER BY SAL DESC. SELECT EMPNO, SAL, HIREDATE FROM EMP ORDER BY DEPTNO ASC; SELECT ENAME, JOB, COMM FROM EMP ORDER BY HIREDATE ASC; SELECT DISTINCT SELECT DISTINCT JOB FROM EMP; SELECT DISTINCT DEPTNO FROM EMP; NULL SELECT * FROM EMP WHERE MGR IS NULL; SELECT * FROM EMP WHERE COMM IS NOT NULL; SELECT * FROM EMP WHERE COMM IS NULL; > < BETWEEN SELECT * FROM EMP WHERE SAL BETWEEN 800 AND 1500; SELECT * FROM EMP WHERE HIREDATE BETWEEN 1980-01-01 AND 1981-01-01; SELECT * FROM EMP WHERE COMM BETWEEN 0 AND 200; LIST SELECT * FROM EMP WHERE JOB IN (SALESMAN, MANAGER, ANALYST); SELECT * FROM EMP WHERE DEPTNO IN (10, 20, 30); SELECT * FROM EMP WHERE SAL IN (800, 1000, 1200); SELECT WITH CONCAT SELECT ENAME, HAS JOB, JOB, WITH SALARY, SAL FROM EMP; SELECT ENAME, WORKS IN, DEPTNO, WITH, SAL FROM EMP; AGGREGATE FUNCTIONS SELECT MAX(SAL) FROM EMP; SELECT MIN(SAL) FROM EMP WHERE DEPTNO=10; SELECT SUM(SAL) FROM EMP WHERE DEPTNO IN (10,20); SELECT AVG(SAL) FROM EMP WHERE DEPTNO IN (10,20); SELECT COUNT(*) FROM EMP WHERE DEPTNO IN (10,20); CREATE CREATE TABLE EMPNEW ( EMPNO Integer(5) ENAME Character(20) JOB Character(20), MGR Integer(3) HIREDATE Date,

PRIMARY KEY, NOT NULL, NOT NULL,

SAL COMM DEPTNO

Float(7,2) Integer(4) Integer(2)

Check (SAL > 0), Default NULL, References DETAILS (DEPTNO)

); INSERT INSERT INTO EMPNEW VALUES (7369,SMITH,CLERK, 7902, 1980-12-17, 800, NULL, 20); INSERT INTO EMPNEW VALUES (7499,ALLEN,SALESMAN, 7698, 1981-02-20, 1600, 300, 30); UPDATE UPDATE EMPNEW SET DEPTNO=10 WHERE ENAME = FORD; UPDATE EMPNEW SET SAL=SAL + SAL *5/100; UPDATE EMPNEW SET COMM=SAL * 10/100 WHERE ENAME = BLAKE; DELETE DELETE FROM EMPNEW WHERE ENAME = BLAKE; DELETE FROM EMPNEW DEPTNO =10; ALTER ALTER TABLE EMPNEW ADD (PHONE CHAR(10)); ALTER TABLE EMPNEW MODIFY ENAME CHAR(30); ALTER TABLE EMPNEW ADD NOT NULL (PHONE); DROP DROP TABLE EMPNEW GROUP BY SELECT COUNT(*) FROM EMP GROUP BY DEPTNO; SELECT AVG(SAL) FROM EMP WHERE DEPTNO IN (10,20) GROUP BY DEPTNO; SELECT MIN(HIREDATE) FROM EMP WHERE GROUP BY DEPTNO HAVING MIN(HIREDATE)>=1998-02-22; JOIN SELECT ENAME, DEPTNO, DNAME FROM EMP, DETAILS WHERE EMP.DEPTNO=DETAILS.DEPTNO; SELECT ENAME, DNAME, LOC FROM EMP, DETAILS WHERE EMP.DEPTNO=DETAILS.DEPTNO AND DAME=FIN; SELECT ENAME, HIREDATE, LOC FROM EMP, DETAILS WHERE EMP.DEPTNO=DETAILS.DEPTNO AND DNAME=MKT; SCALER EXPRESSIONS SELECT ENAME, SAL, COMM, SAL + COMM TOTAL FROM EMP; SELECT ENAME, JOB, MIDDLE (3,4) FROM EMP;

S-ar putea să vă placă și