You are on page 1of 3

SQL Queries

1. Write a query to create Table EMP with columns EMPNO, ENAME, SAL, DESG, HIREDATE, DEPTNO, COMM

CREATE TABLE EMP (EMPNO NUMBER PRIMARY KEY, ENAME CHAR(20) NOT NULL, SAL NUMBER CHECK (SAL>5000), DESG CHAR(10), HIREDATE DATE, DEPTNO NUMBER, COMM NUMBER );

2. Write a query to display all the rows from table Emp.

SELECT * FROM EMP;

3. Write a query to display only those rows whose sal is between 5500 to 7000.

SELECT * FROM EMP WHERE SAL BETWEEN 5500 AND 7000;

4. Write a query to display only those rows from emp whose name starts with A.

SELECT * FROM EMP WHERE NAME LIKE A%; Write a query to display all detals in ascending order of Sal field and descending order of DEPTNO. SELECT * FROM EMP ORDER BY SAL, DEPTNO DESC;

5. Write a query to display no of employees with each deptno.

SELECT DEPTNO, COUNT(*) FROM EMP GROUP BY DEPTNO;

6. Write a query to update the details of table Emp by increasing the salary of each one by 15% whose commission is not given.

UPDATE TABLE EMP SET SAL = SAL + (0.15*SAL) WHERE COMM IS NULL;

7. Write a query to create a view from table EMP which stores all the details whose JOB

type is Manager.

CREATE VIEW V1 AS SELECT * FROM EMP WHERE JOB = MANAGER;

8. Write a query that displays Distinct DEPTNO from table EMP.

SELECT DISTINCT DEPTNO FROM EMP;

9. Write a query to Delete a row from table EMP whose deptno is 40.

DELETE FROM TABLE EMP WHOSE DEPTNO = 40;

10. Write a query to Drop table EMP.

DROP TABLE EMP;

11. Write a query to add a new column PHONENUM in table EMP.

ALTER TABLE EMP ADD PHONENUM NUMBER;

12. Write a query to display Deptno wise Maximum and Minimum Salary from table EMP.

SELECT DEPTNO, MAX(SAL), MIN(SAL) FROM EMP GROUP BY DEPTNO;

13. Write a query to display details of employees by DEPTNO , TOTAL NUM OF EMP, TOTAL SAL, AVERAGE SAL from table EMP whose COMM amount is given.

SELECT DEPTNO, COUNT(*), SUM(SAL), AVG(SAL) FROM EMP GROUP BY DEPTNO HAVING COMM NOT NULL;

14. Write a query to display all details whose job type is either CLERK, MANAGER or ANALYST.

SELECT * FROM EMP WHERE JOB IN (CLERK,MANAGER,ANALYST);

You might also like