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

mysql practical

Uploaded by

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

mysql practical

Uploaded by

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

1) Write the queries for the questions i to iii and find the output for iv to vi with reference to

the below table.

Products

i) Declare the column pid as the primary key.


ii) Show the details of the products which will expire in 2025.
iii) Display the tax on each product which is 5% of the price of the product
iv) SELECT PNAME,EDATE FROM PRODUCTS WHERE EDATE> ‘2026-01-01’;
v) SELECT COO,MAX(PPRICE) FROM PRODUCTS GROUP BY COO.
vi) SELECT SUM(PPRICE) FROM PRODUCTS WHERE EDATE > ‘2026-01-01’.

Ans:

i) ALTER TABLE PRODUCTS ADD PRIMARY KEY(PID);


ii) SELECT * FROM PRODUCTS WHERE EDATE<’2025-12-31’;
iii) SELECT PNAME,PPRICE*0.05 AS TAX FROM PRODUCTS;
iv)

v)

vi)
2) Write the queries for the questions i to iii and find the output for iv to vi with reference to the
below tables.

Students

Feecollection

i) Display Students Name and their Remaining fees.


ii) Display Number of Students from each state.
iii) Display all the data from both the tables.
iv) SELECT STUDENTS.ROLLNO,CLASS, 199000-TOTALFEES AS DISCOUNT FROM
STUDENTS,FEECOLLECTION WHERE STUDENTS.ROLLNO=FEECOLLECTION.ROLLNO;
v) SELECT STUDENTS.CLASS,SUM(FEESPAID) FROM STUDENTS,FEECOLLECTION GROUP BY
CLASS;
vi) SELECT * FROM FEECOLLECTION WHERE TOTALFEES-FEESPAID >120000;

Ans:

i) SELECT STUDENTS.NAME,TOTALFEES-FEESPAID AS REMAININGFEES FROM


STUDENTS,FEECOLLECTION WHERE STUDENTS.ROLLNO=FEECOLLECTION.ROLLNO;
ii) SELECT STATE,COUNT(STATE) FROM STUDENTS GROUP BY STATE
iii) SELECT * FROM STUDENTS NATURAL JOIN FEECOLLECTION
iv)

v)

vi)

3) Write the queries for the questions i to iii and find the output for iv to vi with reference to the
below tables.

Employees

i) Display the list of employees who have joined after 2021.


ii) Display the count of employees for each department.
iii) Show the maximum of salary of each department.
iv) SELECT ENAME,DEPT FROM EMPLOYEES WHERE DOJ> ‘2020-01-01’;
v) SELECT DEPT,MAX(DOJ),MIN(DOJ) FROM EMPLOYEES GROUP BY DEPT;
vi) SELECT ENAME FROM EMPLOYEES WHERE SALARY >25000 ORDER BY DOJ DESC;

Ans:
i) SELECT * FROM EMPLOYEES WHERE DOJ> ‘2021-12-31’;
ii) SELECT DEPT,COUNT(DEPT) FROM EMPLOYEES GROUP BY DEPT;
iii) SELECT DEPT,MAX(SALARY) FROM EMPLOYEES GROUP BY DEPT;
iv)

v)

vi)

4) Write the queries for the questions i to iii and find the output for iv to vi with reference to the
below tables

Games
Players

i) Display the game type and average number of game played in each type.
ii) Display prize money, name of the game and name of the players from the table Games
and Players.
iii) Display the unique games.
iv) SELECT GAMENAME,TYPE FROM GAMES WHERE PRIZEMONEY IS NULL;
v) SELECT TYPE,MAX(PRIZEMONEY),MIN(PRIZEMONEY) FROM GAMES GROUP BY TYPE;
vi) SELECT DISTINCT GCODE FROM PLAYERS;

Ans:

i) SELECT TYPE,AVG(NUMBER) FROM GAMES GROUP BY TYPE;


ii) SELECT PRIZEMONEY, GAMENAME,NAME FROM GAMES, PLAYERS WHERE
GAMES.GCODE=PLAYERS.GCODE;
iii) SELECT DISTINCT TYPE FROM GAMES;
iv)

v)

vi)

5) Write the queries for the questions i to iii and find the output for iv to vi with reference to the
below tables
Rental

i) Add Primary key to the column VID.


ii) Increase the charges of all the cabs by 10%.
iii) Delete all the cabs whose type is SUV.
iv) SELECT DISTINCT TYPE FROM RENTAL;
v) SELECT TYPE,MAX(RATEPERHOUR),MIN(RATEPERHOUR) FROM RENTAL GROUP BY TYPE;
vi) SELECT VNAME FROM RENTAL ORDER BY RATEPERHOUR DESC;

Ans:

i) ALTER TABLE RENTAL ADD PRIMARY KEY(VID);


ii) UPDATE RENTAL SET RENTPERHOUR=RENTPERHOUR*1.1;
iii) DELETE FROM RENTAL WHERE TYPE=’SUV’;
iv)

v)

vi)

You might also like