0% found this document useful (0 votes)
153 views

Class 11 Record

Uploaded by

gshivamihit2808
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
153 views

Class 11 Record

Uploaded by

gshivamihit2808
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

6.

STUDENT DATABASE
Consider the following table Student. Write SQL commands for the statements (i) to (iv) and
give outputs for SQL queries (v) to (vii)
Table: Student
Rno Fname Lname Gender dob marks
1 Abishek Narula M 1998-10-05 98
2 Bishek Pahuja M 1998-12-30 92
3 Bhushan Verma M 1998-02-27 95
4 Chetali Sapra F 1998-06-12 94
5 Chetanya Sharma M 1998-07-29 93
6 Dev Upadhyay F 1998-06-12 84
7 Daksh Arora M 1997-08-14 84
8 Deepakshi Shanu F NULL NULL

Create table student(rno integer,fname varchar(25), lname varchar(25),gender char(2),


dob date,marks integer);

Insert into student values(1,’ Abishek’,’ Narula’,’M’,’ 1998-10-05’,98);


Insert into student values(2,’ Bishek’,’ Pahuja’,’M’,’ 1998-12-30’,92);
Insert into student values(3,’ Bhushan’,’ Verma’,’M’,’ 1998-02-27’,95);
Insert into student values(4,’ Chetali’,’ Sapra’,’F’,’ 1998-06-12’,94);
Insert into student values(5,’ Chetanya’,’ Sharma’,’M’,’ 1998-07-29’,93);
Insert into student values(6,’ Dev’,’ Upadhyay’,’F’,’ 1998-06-12’,84);
Insert into student values(7,’ Daksh’,’ Arora’,’M’,’ 1998-08-14’,84);
Insert into student values(8,’ Deepakshi’,’ Shanu’,’F’,NULL,NULL);

Write the SQL commands for the following using above tables:
i. To display the details of students who have got marks greater than 90.
select fname, marks from student where marks > 90;
ii. To display firstname,lastname and marks of the students whose marks are from 92 to
95.
select fname, lname, marks FROM student WHERE marks BETWEEN 92 and 95;
iii. To display the records in ascending order of marks and descending order of firstname
who have got marks greater than 90.
select fname, lname , marks from STUDENT WHERE marks >90 ORDER BY marks
ASC, fname DESC;
iv. To update date of birth and marks column to 2004-03-23 and 90 of a student
Deepakshi.
Update student set dob=’2004-03-23’,marks=90 where name=”Deepakshi”;
Give the output for the following SQL commands:
v. Select DISTINCT marks from student;
marks
98
92
95
94
93
84
NULL

vi. select fname from student where gender ='f' and marks>90;
fname
Chetali

vii. select * from student where fname like ‘A%’;


Rno Fname Lname Gender dob marks
1 Abishek Narula M 1998-10-05 98

Result:
Thus the above SQL queries was executed successfully.
7. FITNESS PRODUCTS DATABASE
Consider the following table Gym. Write SQL commands for the statements (i) to (iv) and give
outputs for SQL queries (v) to (vii)

Table: Gym
Prcode Prname Price Manufacturer
P101 Cross Trainer 25000 Avon Fitness
P102 TreadMill 32000 AG Fitline
P103 Massage Chair 20000 Fit Express
P104 Vibration Trainer 22000 Avon Fitness
P105 Bike 13000 Fit Express

Create table gym(prcode char(6),prname varchar(30),price integer,manufacturer


varchar(30));

Insert into gym values(‘P101’,’Gross Trainer’,25000,’Avon Fitness’);


Insert into gym values(‘P102’,’Tread Mill’,32000,’AG Fitline’);
Insert into gym values(‘P103’,’Massage chair’,20000,’ Fit Express’);
Insert into gym values(‘P104’,’Vibration Trainer’,22000,’Avon Fitness’);
Insert into gym values(‘P105’,’Bike’,13000,’Fit Express’);

Write the SQL commands for the following using above tables:

i. To Display the names and unit price of all the products in the store
select prname,price from gym;

ii. To Display names of all products by the manufacturer "Fit Express".


select prname from gym where manufacturer ="Fit Express";

iii. To Change the Unit Price data of all the rows by applying a 10% discount reduction on
all the products.
Update gym set price=price-price*0.1 ;

iv. To Display the names of all the products with unit price less than Rs.20000.00
select prname from gym where price < 20000;
Give the output for the following SQL commands:
v. Select * from gym where price between 20000 and 30000;
Prcode Prname Price Manufacturer
P101 Cross Trainer 25000 Avon Fitness
P103 Massage Chair 20000 Fit Express
P104 Vibration Trainer 22000 Avon Fitness

vi. select * from gym where Price >=25000 and manufacturer=’avon fitness’;
Prcode Prname Price Manufacturer
P101 Cross Trainer 25000 Avon Fitness

vii. select * from gym where manufacturer like ‘A%’;


Prcode Prname Price Manufacturer
P101 Cross Trainer 25000 Avon Fitness
P102 TreadMill 32000 AG Fitline
P104 Vibration Trainer 22000 Avon Fitness

Result:
Thus the above SQL queries was executed successfully.
8. EMPLOYEE AND SALARY DATABASE
Consider the following tables Employee and Salary. Write SQL commands for the statements (i)
to (iv) and give outputs for SQL queries (v) to (vii)

Table: Employee
Eid Name Depid Qualification Gender
1 Deepali Gupta 101 MCA F
2 Rajat Tyagi 101 BCA M
3 Hari Mohan 102 B.A. M
4 Harry 102 M.A. M
5 Sumit Mittal 103 B.Tech. M
6 Jyoti 101 M.Tech. F
Table: Salary

Eid Basic D.A HRA Bonus


1 6000 2000 2300 200
2 2000 300 300 30
3 1000 300 300 40
4 1500 390 490 30
5 8000 900 900 80
6 10000 300 490 89
create table employee(Eid integer, Name varchar(30),Depid integer, Qualification varchar(30),
Gender char(3));

insert into employee values(1,'Deepali Gupta',101,'MCA','F');


insert into employee values(2,'Rajat Tyagi',101,'BCA','M');
insert into employee values(3,'Hari Mohan',102,'B.A','M');
insert into employee values(4,'Harry',102,'MA','M');
insert into employee values(5,'SumitMittal',103,'B.TECH','M');
insert into employee values(6,'Jyoti',101,'M.TECH','F');

create table salary(Eid integer, Basic integer, DA integer, HRA integer, Bonus integer);

insert into salary values(1,6000,2000,2300,200);


insert into salary values(2,2000,300,300,30);
insert into salary values(3,1000,300,300,40);
insert into salary values(4,1500,390,490,30);
insert into salary values(5,8000,900,900,80);
insert into salary values(6,10000,300,490,89);
Write the SQL commands for the following using above tables:

i. To display the details of all the employee.


Select * from employee;
ii. To list the names of those employee only whose name starts with ‘H’
Select name from employee where name like ‘H%’;
iii. To add a new column in salary table. The column name is Total_Sal.
Alter table salary add Total_sal integer;
iv. To store the corresponding values in the Total_Sal column.
select basic,DA,HRA,Bonus,(Basic+DA+HRA+Bonus) AS Total_sal from salary;

Give the output for the following SQL commands:


v. Select max(Basic) from salary where Bonus > 40;
Max(Basic)
10000

vi. Select count(*) from Employee group by Gender;


Count(*)
4
2

vii. Select Distinct Depid from Employee;


Depid
101
102
103

Result:
Thus the above SQL queries was executed successfully.
9. EMPLOYEE AND EMPSALARY DATABASE
Consider the following tables Employees and EmpSalary. Write SQL commands for the
statements (i) to (iv) and give outputs for SQL queries (v) to (vii)
Table: Employees

EmpId Firstname Lastname Address City


010 Ravi Kumar Raj nagar GZB
105 Harry Waltor Gandhi nagar GZB
152 Sam Tones 33 Elm st Paris
215 Sarah Ackerman 440 U.S. 110 Upton
244 Manila Sengupta 24 Friends street New Delhi
300 Robert Samuel 9 Fifth Cross Washington
335 Ritu Tondon Shastri nagar GZB
400 Rachel Lee 121 Harrison st. New York
441 Peter Thomson 11 Red Road Paris
Table: Empsalary
Empid Salary Benefits Designation
010 75000 15000 Manager
105 65000 15000 Manager
152 80000 25000 Director
215 75000 12500 Manager
244 50000 12000 Clerk
300 45000 10000 Clerk
335 40000 10000 Clerk
400 32000 7500 Salesman
441 28000 7500 Salesman
create table employees(Empid integer ,Firstname varchar(30), lastname varchar(30),Address
varchar(30),City varchar(30));
insert into employees values(010,'Ravi','Kumar','Raj nagar','GZB');
insert into employees values(105,'Harry','Waltor','Gandhi Nagar','GZB');
insert into employees values(152,'Sam','Tones','33 Elm st','Paris');
insert into employees values(215,'Sarah','Ackerman','440 U.S 110','Upton');
insert into employees values(244,'Manila','Sengupta','24 Friends street','New Delhi');
insert into employees values(300,'Robert','Samuel','9 fifth cross','Washington');
insert into employees values(335,'Ritu','Tondon','Shastri nagar','GZB');
insert into employees values(400,'Rachel','Lee','121 Harrison st','New York');
insert into employees values(441,'Peter','Thomson','11 Red road','Paris');
create table empsalary(Empid integer,Salary integer,Benefits integer ,Designation char(30));
insert into empsalary values(010,75000,15000,'Manager');
insert into empsalary values(105,65000,15000,'Manager');
insert into empsalary values(152,80000,25000,'Director');
insert into empsalary values(215,75000,12500,'Manager');
insert into empsalary values(244,50000,12000,'Clerk');
insert into empsalary values(300,45000,10000,'Clerk');
insert into empsalary values(335,40000,10000,'Clerk');
insert into empsalary values(400,32000,7500,'Salesman');
insert into empsalary values(441,28000,7500,'Salesman');

Write the SQL commands for the following using above tables:

i. To display firstname, lastname, address and city of all employees living in Pairs.
select Firstname,Lastname,Address,City from employees where city='Paris';

ii. To display the content of Employees table in descending order of Firstname.


select * from employees order by Firstname desc;

iii. To display the firstname, lastname and total salary of all managers from the tables
Employees and EmpSalary, where total salary is calculated as salary + Benefits.
alter table empsalary ADD TotalSalary integer;
select salary,benefits,(salary+benefits) AS TotalSalary from empsalary;
select * from empsalary;

iv. To display the maximum salary among managers from the table Empsalary.
select max(salary) from empsalary where designation=’manager’;
Give the output for the following SQL commands:

v. Select firstname, Salary from Employees, Empsalary where Designation = ‘Salesman’ and
Employees.Empid = Empsalary.Empid;
Firstname Salary
Rachel 32000
Peter 28000

vi. Select distinct designation from EmpSalary ;

Designation
Clerk
Director
Manager
Salesman

vii. Select sum(Benefits) from EmpSalary where Designation =’Clerk’;

Benefits
32000

Result:
Thus the above SQL queries was executed successfully.
10. GARMENT AND FABRIC DATABASE
Consider the following tables GARMENT and FABRIC. Write SQL commands for the statements
(i) to (iv) and give outputs for SQL queries (v) to (viii)
Table: GARMENT
GCODE Description price FCODE READYDATE
10023 PENCIL SKIRT 1150 F03 19-DEC-08
10001 FORAML SHIRT 1250 F01 12-JAN-08
10012 INFORMAL SHIRT 1550 F02 06-JUN-08
10024 BABY TOP 750 F03 07-APR-07
10090 TULIP SKIRT 850 F02 31-MAR-07
10019 EVENING GOWN 850 F03 06-JUN-08
10009 INFORMAL PANT 1500 F02 20-OCT-08
10007 FORMAL PANT 1350 F01 09-MAR-08
10020 FROCK 850 F04 09-SEP-07
10089 SLACKS 750 F03 31-OCT-08
Table: FABRIC
FCODE TYPE
F04 POLYSTER
F02 COTTON
F03 SILK
F01 NYLON
create table garment(GCODE integer,Description varchar(30),price integer,FCODE
varchar(30),READYDATE varchar(20));

insert into garment values(10023,'pencil skirt',1150,'F03','19-DEC-08');


insert into garment values(10001,'formal shirt',1250,'F01','12-JAN-08');
insert into garment values(10012,'informal shirt',1550,'F02','06-JUN-08');
insert into garment values(10024,'baby top',750,'F03','07-APR-07');
insert into garment values(10090,'tulip skirt',850,'F02','31-MAR-07');
insert into garment values(10019,'evening gown',850,'F03','06-JUN-08');
insert into garment values(10009,'informal pant',1500,'F02','20-OCT 08');
insert into garment values(10007,'formal pant',1350,'F01','09-MAR-08');
insert into garment values(10020,'frock',850,'F04','09-SEP-07');
insert into garment values(10089,'slacks',750,'F03','31-OCT-08');

create table fabric(FOCDE varchar(10),TYPE varchar(30));


insert into fabric values('F04','POLYSTER');
insert into fabric values('F02','COTTON');
insert into fabric values('F03','SILK');
insert into fabric values('F01','NYLON');
Write the SQL commands for the following using above tables:
i. To display GCODE and DESCRIPTION of each GARMENT in descending order of GCODE.
select Gcode,Description from garment order by gcode desc;

ii. To display the details of all the GARMENT, which have READYTYPE in between 08-DEC-07
and 16-JUN-08 (inclusive of both the dates)
select * from garment where readydate between '08-DEC-07' and '16-JUN-08';

iii. To display the average PRICE of all GARMENT, which are made up of FABRIC with FCODE as
FO3.
select avg(price) from garment where fcode ='f03';

iv. To display FABRIC wise highest and lowest price of GARMENT from GARMENT table.(display
FCODE of each GARMENT along with highest and lowest price)
select fcode, max(price),min(price) from garment group by fcode;

Give the output for the following SQL commands:


v. select sum (price)from garment where fcode = ‘f01’ ;
SUM(PRICE)
2600

vi. select decription type from garment, fabric where garment.fcode = fabric.fcode and
garment.price>=1260 ;
Description TYPE
informal shirt COTTON
informal pant COTTON
formal pant NYLON

vii. select count(distinct price) from garment;


COUNT(PRICE)
7

Result:
Thus the above SQL queries was executed successfully.
11. ITEM AND CUSTOMER DATABASE
Consider the following tables Item and Customer. Write SQL commands for the Statement (i)
to (iv) and give outputs for SQL queries (v) to (viii)
Table: ITEM
Itemid ItemName Manufacturer Price
PC01 Personal Computer Intel 35000
LC05 Laptop Intel 55000
PC03 Personal Computer HP 32000
PC06 Personal Computer Compaq 37000
LC03 Laptop Apple 57000

Table: CUSTOMER
Cusid CustomerName City Itemid
01 N Roy Delhi LC03
06 H Singh Mumbai PC03
12 R Pandey Delhi PC06
15 C Sharma Delhi LC03
16 K Agrawal Banglore PC01

create table item(Itemid varchar(10),Itemname char(50),Manufacturer char(10),Price integer);

insert into item values('PC01','Personal computer','intel',35000);


insert into item values('LC05','Laptop','intel',55000);
insert into item values('PC03','Personal computer','hp',32000);
insert into item values('PC06','Personal computer','compaq',37000);
insert into item values('LC03','Laptop','Apple',57000);

create table customer(Cusid integer,Customername char(50),City char(10),


Itemid varchar(10));

insert into customer values(01,'N Roy','Delhi','LC03');


insert into customer values(06,'H Singh','Mumbai','PC03');
insert into customer values(12,'R Pandey','Delhi','PC06');
insert into customer values(15,'C Sharma','Delhi','LC03');
insert into customer values(16,'k Agrawal','Banglore','PC01');
Write the SQL commands for the following using above tables:
i. To display the details of those Customers whose City is Delhi.
select * from customer where city='Delhi';
ii. To display the details of Item whose Price is in the range of 35000 to 55000 (Both values
included)
select * from item where price between 35000 and 55000;

iii. To display the CustomerName, City from table Customer, and ItemName and Price from
table Item, with their corresponding matching Itemid
select customername,city,itemname,price from item,customer where
item.itemid=customer.itemid;

iv. To increase the Price of all Items by 1000 in the table item
update item set price=price+1000;

Give the output for the following SQL commands:


v. select distinct city from customer ;
City
Delhi
Mumbai
Banglore

vi. SELECT CustomerName, Manufacturer FROM Item, Customer WHERE Item.Itemid =


Customer.Itemid ;

customername Manufacturer
N Roy Apple
H Singh Hp
R Pandey compaq
C Sharma Apple
k Agrawal intel

vii. SELECT ItemName, Price * 10 FROM Item Where Manufacturer = ‘Intel’;


Itemname ItemName
Personal computer 350000
Laptop 550000

Result:
Thus the above SQL queries was executed successfully.
12. IF ELSE IF STATEMENT
AIM:
To create if else something program using java

ALGORITHM:
1. Start the program
2. Get the input from the user
3. Check the inputs based on conditions
4. If the conditions is true, block will execute
5. If the condition is false, else if block will execute
6. Stop the program

PROGRAM:
import java.util.Scanner;
public class ifelse
{
public static void main(String[] args)
{
int number;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
number=sc.nextInt();
if(number>0)
System.out.println("The number is positive.");
else if(number<0)
System.out.println("The number is Negative.");
else
System.out.println("The number is 0");
}

}
OUTPUT:
Enter the number
9
The number is positive.
Enter the number
-7
The number is Negative.
Enter the number
0
The number is 0

RESULT:
Thus the above Java Program was Executed Successfully.
13. SWITCH CASE STATEMENT
AIM:
To create a switch case while statement program using java
ALGORITHM:
1. Start the program
2. Get the input with the case value
3. Match the input with case value
4. If match case, execute that case output statement
5. If no match case, default statement will be executed
6. Stop the program
PROGRAM:
import java.util.Scanner;
public class switchcase
{
public static void main(String[] args)
{
int daynum;
Scanner sc=new Scanner(System.in);
System.out.println("Enter a day number (1-7):");
daynum=sc.nextInt();
switch(daynum)
{
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
case 4:
System.out.println("Thursday");
break;
case 5:
System.out.println("Friday");
break;
case 6:
System.out.println("Saturday");
break;
case 7:
System.out.println("Sunday");
break;
default:
System.out.println("Invalid day number.");
break;
}
}
}

OUTPUT:
Enter a day number (1-7):
3
Wednesday
Enter a day number (1-7):
6
Saturday
Enter a day number (1-7):
9
Invalid day number.

RESULT:
Thus the above Java Program was Executed Successfully.
14. WHILE STATEMENT
AIM:
To create a while statement program using java
ALGORITHM:
1. Start the program
2. Get the input from the user
3. Check the initial value and the condition
4. If the condition is true, execute the loop till it becomes false
5. Stop the program

PROGRAM:
import java.util.Scanner;
public class whileexample
{
public static void main(String[] args)
{
int i;
System.out.println("Enter the value:");
Scanner sc=new Scanner(System.in);
i=sc.nextInt();
while(i<=10)
{
System.out.println(i);
i++;
}
}

}
OUTPUT:
Enter the value: 5
5
6
7
8
9
10
RESULT:
Thus the above Java Program was Executed Successfully.
15. Do while statement
AIM:
To create a do while statement program using java
ALGORITHM:
1. Start the program
2. Get the input from the user
3. Execute the loop
4. Check the increment or document operation and check the condition statement
5. Stop the program
PROGRAM:
import java.util.Scanner;
public class dowhileexample
{
public static void main(String[] args)
{
int i;
System.out.println("Enter the value:");
Scanner sc=new Scanner(System.in);
i=sc.nextInt();
do
{
System.out.println(i);
i++;
}
while(i<=10);
}

OUTPUT:
Enter the value: 7
7
8
9
10

RESULT:
Thus the above Java Program was Executed Successfully.

You might also like