0% found this document useful (0 votes)
4 views3 pages

Cs-Lab-Manual Part-2 (Mysql)

The document provides SQL statements for creating and manipulating two tables: STUDENT and PLAYER, including DDL and DML operations. It also includes various queries to retrieve specific data from these tables, such as discounts, maximum fees by gender, and player salaries. Additionally, it covers the creation of PASSENGER and FLIGHT tables with corresponding queries to update fares and count passengers by gender.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Cs-Lab-Manual Part-2 (Mysql)

The document provides SQL statements for creating and manipulating two tables: STUDENT and PLAYER, including DDL and DML operations. It also includes various queries to retrieve specific data from these tables, such as discounts, maximum fees by gender, and player salaries. Additionally, it covers the creation of PASSENGER and FLIGHT tables with corresponding queries to update fares and count passengers by gender.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL

(A) Consider the following table STUDENT and write SQL statements for the question no (i)
to (iii) and find outputs for the queries (iv) and (v) :

ROLL SNAME SEX DOB FEES


S1 MEENA F 2007-03-24 2400
S2 ROHIT M 2006-09-17 3200
S3 KUMAR M 2006-12-29 2700
S4 DIVYA F 2007-02-03 2300
S5 AYUSH M 2006-10-21 3600

(1) Write a DDL statement to create the above table.

CREATE TABLE STUDENT


( ROLL CHAR(2),
SNAME VARCHAR(20),
SEX CHAR(1),
DOB DATE,
FEES INTEGER ) ;

(2) Write a DML statement to insert any one record in the above table.

INSERT INTO STUDENT


VALUES ( “S1” , “MEENA” , “F” , “2007-03-24” , 2400 ) ;

(3) Write a query to display SNAME and FEES of those students whose
DOB is earlier than 31-12-2006.

SELECT SNAME , FEES


FROM STUDENT
WHERE DOB < ‘2006-12-31’ ;

(4) SELECT SNAME , FEES * 0.1 “DISCOUNT” FROM STUDENT


WHERE FEES BETWEEN 2500 AND 3500;

SNAME DISCOUNT
ROHIT 320
KUMAR 270

(5) SELECT SEX , MAX(FEES) FROM STUDENT GROUP BY SEX ;

SEX MAX(FEES)
F 2400
M 3600

(6) Write query to display SNAME and DOB of those students whose SNAME ends with ‘A’.

SELECT SNAME , DOB


FROM STUDENT
WHERE SNAME LIKE “%A” ;

(7) SELECT SNAME, FEES FROM STUDENT WHERE SEX = ‘M’ ORDER BY DOB ;
SNAME FEES
ROHIT 3200
AYUSH 3600
KUMAR 2700

(8) SELECT COUNT(DISTINCT SEX) FROM STUDENT ;


COUNT ( DISTINCT SEX )
2
(B ) Consider the following table PLAYER and write SQL statements for the question and
find outputs for the queries :

PID PNAME SALARY GAME RANK


P1 MEENA 5000 CRICKET 5
P2 ROHIT 8000 BADMINTON 9
P3 KUMAR 4000 TENNIS 15
P4 DIVYA 9000 CRICKET 1
P5 AYUSH 6000 BADMINTON 20

(1) Write a DDL statement to create the above table.


CREATE TABLE PLAYER

( PID CHAR(2),
PNAME VARCHAR(20),
SALARY INTEGER,
GAME VARCHAR(20),
RANK INTEGER ) ;

(2) Write a DML statement to insert any one record in the above table.
INSERT INTO PLAYER
VALUES ( “P1” , “MEENA” , 5000 , “CRICKET” , 5 ) ;

(3) Display player id, player name , salary and rank whose game
is other than Tennis or Cricket.
SELECT PID , PNAME , SALARY , RANK
FROM PLAYER
WHERE GAME NOT IN [ “TENNIS” , “CRICKET” ] ;

(4) UPDATE PLAYER SET SALARY = SALARY + 500


WHERE RANK <= 5 AND GAME = ‘CRICKET’ ;
PID PNAME SALARY GAME RANK
P1 MEENA 5500 CRICKET 5
P2 ROHIT 8000 BADMINTON 9
P3 KUMAR 4000 TENNIS 15
P4 DIVYA 9000 CRICKET 1
P5 AYUSH 6000 BADMINTON 20

(5) SELECT GAME , COUNT(*) FROM PLAYER


GROUP BY GAME HAVING COUNT(*) > 1;
GAME COUNT(*)
CRICKET 2
BADMINTON 2

(6) Display the count of all players whose game is Cricket.


SELECT GAME , COUNT(*)
FROM PLAYER
GROUP BY GAME
HAVING GAME = “CRICKET” ;

(7) SELECT GAME , SUM(SALARY) , COUNT(*) FROM PLAYER GROUP BY GAME ;


GNAME SUM(SALARY) COUNT(*)
CRICKET 14000 2
BADMINTON 14000 2
TENNIS 4000 1

(8) SELECT PID , PNAME FROM PLAYER WHERE SALARY BETWEEN


5000 AND 8000 ORDER BY GAME DESC;

PID PNAME
P2 ROHIT
P1 MEENA
P5 AYUSH
(C) Consider the following table and write SQL statements for the question and find
outputs for the queries :
Table : PASSENGER Table : FLIGHT
PNO NAME GENDER FNO FNO START END FARE
1001 SURESH MALE F101 F101 MUMBAI CHENNAI 4500
1002 ANITA FEMALE F104 F102 MUMBAI BENGALURU 4000
1003 HARJAS MALE F102 F103 DELHI CHENNAI 5500
1004 NITA FEMALE F103 F104 KOLKATA MUMBAI 4500

(1) Write a DDL statement to create the above tables.


CREATE TABLE PASSENGER CREATE TABLE FLIGHT
( PNO INTEGER PRIMARY KEY , (FNO CHAR(4) PRIMARY KEY ,
NAME VARCHAR(10), START VARCHAR(10),
GENDER VARCHAR(10), END VARCHAR(10),
FNO CHAR(4) REFERENCES FLIGHT(FNO) ) ; FARE INTEGER ) ;

(2) Write a DML statement to insert any one record in the above tables.
INSERT INTO PASSENGER
VALUES ( 1001 , “SURESH” , “MALE” , “F101” ) ;

INSERT INTO FLIGHT


VALUES ( “F101” , “MUMBAI” , “CHENNAI” , 4500 ) ;

(3) Write a query to change the fare to 6000 of the flight whose FNO is F104.
UPDATE FLIGHT
SET FARE = 6000
WHERE FNO = “F104” ;

(4) Write a query to display the total number of MALE and FEMALE PASSENGERS.
SELECT GENDER , COUNT(*)
FROM PASSENGER
GROUP BY GENDER ;

(5) Write a query to display the NAME , GENDER , corresponding FARE of all PASSENGERS
who have a flight to START from DELHI.
SELECT NAME , GENDER , FARE
FROM PASSENGER , FLIGHT
WHERE PASSENGER.FNO = FLIGHT.FNO AND START = “DELHI” ;

COMMANDS :

(1) SHOW DATABASES ;

(2) CREATE DATABASE <database_name> ;

(3) USE <database_name> ;

(4) SHOW TABLES ;

(5) DESC <table_name>

(6) SELECT * FROM <table_name>

(7) DROP TABLE <table_name>

(8) DROP DATABASE <database_name>

You might also like