Sqlassignment

You might also like

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

STRUCTURE QUERY LANGUAGE

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
1.

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 employees 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: Select COUNT(*) from Emp;
Select MIN(Sal) from Emp where
deptno=20;
Select SUM(Sal) from Emp
where job=Clerk;
Select AVG(sal) from Emp;
Select
job,max(sal),min(sal),avg(sal) from emp group by job;
Select empno,ename,sal+comm
total Salary from emp;
Select * from emp where
hiredate< 12/12/

Consider a table Department having fields as


Deptno
Deptname
Integer
Character

Display name of employees along with their


department having deptno as 10 or 20.

Display total salary of each department.

Display total salary of each department whose


employee name starts with N or P.

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).


No.
Number(4)

No
1
2
3
4
5
6
7
8

Customer
Fname
Lname
Phone
Address
Character(20) Character(20) Number(8)
Character(20)
Create the table
Enter following data
Fname
Lname
Phone
Address
Ajay
Batra
27111333
Rohini
Deepak
Chopra
25656891
Ashok Vihar
Rajesh
Mehta
23455511
Ashok Vihar
Priya
Kumar
23456334 Rohini
Ramit
Arya
24567565 Model Town
Arpit
Jain
23222334 Shailmar Bagh
Rahul
Kundra
24567856 Model Town
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

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.
1.

You might also like