SQL Questions
SQL Questions
table ‘sports’. Now, SAI wants to perform some queries on sports table that is already been
created in database. Therefore, Write mentioned five SQL queries to facilitate SAI:-
Table: sports
Query (1): Show details of those players whose name start with ‘K’.
Query(2):Delete the records of those players whose gender in unknown (null).
Query (3): Show name of those players whose age is between 20 and 30.
Query (4): Show details of those players who play either Karate or Squash.
Query (5):Increase (update) the 15% pay of all the players.
Ans:
(1) select * from sports where pname like ‘K%’;
(2) delete from sports where gender is null;
(3) select pname from sports where age between 20 and 30;
(4) select * from sports where sname in(‘Karate’,‘Squash’);
(5) update sports set pay=pay+(pay*15)/100;
Q: Perform the below queries in MySql database using SQL:
Ans:
(i) 63
(ii) 800
(iii) 475
Write SQL commands for the following queries (i) to (v) based on the relations Teacher and Posting given
below:
TABLE : TEACHER
T_ID Name Age Department Date_of_join Salary Gender
1 Jugal 34 Computer Sc 10-01-2017 12000 M
2 Sharmila 31 History 24-03-2008 20000 F
3 Sandeep 32 Mathematics 12-12-2016 30000 M
4 Sangeeta 35 History 01-07-2015 40000 F
5 Rakesh 42 Mathematics 05-09-2007 25000 M
6 Shyam 50 History 27-06-2008 30000 M
7 Shiv Om 44 Computer Sc 25-02-2017 21000 M
8 Shalakha 33 Mathematics 31-07-2018 20000 F
Consider the following table named “Product”, showing details of products being sold in a grocery shop.
Table : Product
PCode PName UPrice Manufacturer
P01 Washing Powder 120 Surf
P02 ToothPaste 54 Colgate
P03 Soap 25 Lux
P04 ToothPaste 65 Pepsodant
P05 Soap 38 Dove
P06 Shampoo 245 Dove
Write SQL queries for the (i) and (ii) and write output of queries (iii) ,(iv) and (v)
i. List the Product Code, Product name and price in descending order of their price
She wants to display maximum salary department wise. She wrote the following command:
SELECT Deptcode, Max(Salary) FROM Employee; But she did not get the desired result. Rewrite
the above query with necessary changes to help her get the desired output.