You are on page 1of 2

STRUCTURE QUERY LANGUAGE

1. Write the outputs of SQL commands given in (h) with the help of the table shown.
EmpNo Name Job Mgr Hiredate Sal Deptno
Integer Character Character Float Date Float Integer

 To select all the information of employee of Dept number 20


 Find all employees who are either Clerks or who are earning between 1000 and
2000.
 To list names of all employees in ascending order of their salary.
 To display employee’s name, Salary, Deptno for only managers.
 To count the number of employees with salary <3000.
 To insert a new row in the Employee table with the following data: 11, “MILLER”,
“Manager”, 7698, {25/02/98}, 4300, 20.
 To display total salary department wise.
 To display employees whose name starts with ‘C’
 To display employees whose salary between 1000 to 5000 arranged on the basis
of hiredate
 Give the output of the following SQL statements: -
o Select COUNT(*) from Emp;
o Select MIN(Sal) from Emp where deptno=20;
o Select SUM(Sal) from Emp where job=’Clerk’;
o Select AVG(sal) from Emp;
o Select job,max(sal),min(sal),avg(sal) from emp group by job;
o Select empno,ename,sal+comm “total Salary” from emp;
o Select * from emp where hiredate<’ ‘ 12/12/
 Consider a table Department having fields as
Deptno Deptname
Integer Character
o Display name of employees along with their department having deptno as 10
or 20.
o Display total salary of each department.
o Display total salary of each department whose employee name starts with
N or P.
o Display total salary of each department whose total salary > 20000.

2. Write the SQL command for (a) to (f) on the basis of the table given below
(Customer).
Customer
No. Fname Lname Phone Address
Number(4) Character(20) Character(20) Number(8) Character(20)
 Create the table
 Enter following data
No Fname Lname Phone Address
1 Ajay Batra 27111333 Rohini
2 Deepak Chopra 25656891 Ashok Vihar
3 Rajesh Mehta 23455511 Ashok Vihar
4 Priya Kumar 23456334 Rohini
5 Ramit Arya 24567565 Model Town
6 Arpit Jain 23222334 Shailmar Bagh
7 Rahul Kundra 24567856 Model Town
8 Kisan Kumar 27898981 Rohini

 To select all the information of employee of Rohini area.


 Update the database set the phone no. as 27111343 where phone number is
27111333.
 To create a view called Dir with the following fields-> Fname, Phone and Address.
 To display the data for Arpit, Rahul and Kisan.
 To delete the rows where the address is Rohini.
 Display record on the basis of Fname
 Display number of records
Create another table Sale
No Itemcode Quantity Rate
Number(4) Number(4) Number(7) Number(8,2)
Add the following data
No Itemcode Quantity Rate
1 1001 20 34.56
1 1002 30 67.56
3 1001 20 34.56
4 1009 13 359.23
5 1010 15 699.99
3 1008 16 345.34

 Display Fname,Lname, amount paid(Quantity* Rate) from customer and sale tables
 Display total amount paid by each customer
 Display itemcode,fname, lname from cutomer and sale table
 Try this out and write the output
1.Select No,count(*) from customer C, Sale S where C.No=S.No;
2.Select * from customer where Fname loke ‘A%’ order by Address
3.Select Fname, Quantity,Rate from Customer C, Sale S where C.No=S.No;
4.Select No, Sum(quantity) from Sale group by No;
5.Select No,Lname,sum(quantity) from customer C and Sale S group by No having
C.no=S.No a
 To delete the tables physically.

You might also like