Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 3

Example1

lists the number of Employes in each department

SELECT COUNT(empno), deptno

FROM Emp

GROUP BY deptno;

Example 2

Total amount of the salary in each department

Select deptno, sum(sal) as totalsalary from Emp

Group by deptno;

or

Select deptno, sum(sal) as totalsalary from Emp

Group by deptno

Order by deptno;

Example 3

Q Total amount of the salary on each employee

Select ename, sum(sal) from Emp

Group by ename

1. Write a query to display the name and salary of employees

earning more than 2850

SQL> Select ename, sal from emp where sal>2850;

2. Write a query to display the name and department number

for employee number 7856

SQL> Select name, deptno from emp where empno=7856

3. Displays employees' name and new salary after the

increment of 1000
SQL> select ename, (sal*1000) from emp ;

4. Write a query to display the name and department number

of all employees in departments 10 and 30 in alphabetical

order by name

Select ename,deptno from emp

Where deptno=10 or deptno=30

Order by ename;

5. Write a query to display the name and salary of employees

who earned more than 1500 and are in department number

10 or 30

Select ename,sal from emp

Where sal>1500 and deptno in(10,30,40);

6. Write a query in SQL to list the employees whose salaries

are less than 3500

Select ename,sal from emp

Where sal<3500;

7. Write a query in SQL to list all the employees of designation

CLERK in department no 20.

Select * from emp

Where job=’CLERK’ and deptno=20;

8. Write a query in SQL to list the employees who joined

before 1991.

Select * from emp

Where hiredate <(‘1-1-1991’)

Hiredate<1991
9.Write a query in SQL to display the average salaries of all

the employees who works as ANALYST.

Select avg(sal) from emp

Where job=’ANALYST’

You might also like