DBMS Week - 7 (1) (1) 1
DBMS Week - 7 (1) (1) 1
AIM: create a table with necessary pk,fk,and constraints(age is greater than 20,pmobile must be
unique)
SQL QUERY:
create table passenger (Pid INT, Pname varchar(30), age INT ,pmobile number(20),pmailid
varchar (40),plocation varchar (30),pbalance number(30),PRIMARY
KEY(Pid),CHECK(age>=20),UNIQUE(pmobile));
INSERT INTO passenger values(101,'lokesh',39,911212131,'[email protected]','banglore',20000)
INSERT INTO passenger values(102,'rajesh',65,9112121312,'[email protected]','delhi',15000)
INSERT INTO passenger values(103,'ramesh',60,9112121313,'[email protected]','hyderabad',30000)
INSERT INTO passenger values(104,'divya',45,9112121315,'[email protected]','mumbai',250000)
INSERT INTO passenger values(105,'meghana',20,91121213156,'[email protected]','New
Delhi',1500000)
INSERT INTO passenger values(160,'ashmitha',26,9391063700,'[email protected])
SQL QUERY:
create table reservation(rid INT, rdate Date, rtype varchar(10),rpid INT,rfrom varchar(12),fto
varchar(15),rprice number(10),PRIMARY KEY(rid),FOREIGN KEY(rpid) references passenger(Pid));
INSERT INTO reservation values(1101,'25nov2022','1ac',101,'banglore','chennai',2000);
INSERT INTO reservation values(1102,'18aug2022','2ac',102,'delhi','hyderabad',3000);
INSERT INTO reservation values(1103,'25aug2022','1ac',103,'hyderabad','chennai',1500);
INSERT INTO reservation values(1104,'30aug2022','2ac',104,'delhi','hyderabad',3000);
INSERT INTO reservation values(1105,'28sep2022','2ac',105,'banglore','hyderabad',5000);
SQL QUERY: select count(*) from reservation where rdate like '%AUG%';
AIM: list the passengers who are from hyderabad, banglore
SQL QUERY:
select passenger_name from passenger where plocation ='hyderabad' or plocation='banglore'
AIM: list the passengers who are from New delhi or mumbai
SQL QUERY: select passenger_name from passenger where plocation ='New Delhi' or plocation='mumbai'
AIM: SQL statement that selects all passenegrs from the "passenegers" table, sorted ascending by the "plocation" and
descending by the "pname" column
SQL QUERY:
select * from passenger ORDER BY plocation ASC,passenger_name DESC;
AIM: find the average, minimum and maximum price of tickets in reservation table and rename the columns accordingly
SQL QUERY: select min(rprice) as minimum,max(rprice) as maximum,avg(rprice) as average from reservation
AIM: find how many passengers are the in the passeneger table
SQL QUERY: select count(Pid) from passenger
AIM: SQL statement lists the number of passenger in each plocation, sorted high to low
SQL QUERY: select count(plocation),plocation from passenger GROUP BY plocation ORDER BY
count(plocation) DESC
AIM: in SQL create a view that selects every passenger in the "passenegr" table with a price higher
than the average price
SQL QUERY: CREATE VIEW name_pass as select passenger_name from passenger
AIM: in sql find the passenger details who are senior citizens
SQL QUERY: select * from passenger where age>=60