WORKSHEET SQL
WORKSHEET SQL
TABLE: TRANSACT
TRNO ANO AMOUNT TYPE DOT
T001 101 2500 Withdraw 2017-12-21
T002 103 3000 Deposit 2017-06-01
T003 102 2000 Withdraw 2017-05-12
T004 103 1000 Deposit 2017-10-22
T005 102 12000 Deposit 2017-11-06
(i) To display details of all transactions of TYPE Withdraw from TRANSACT table
(ii) To display ANO and AMOUNT of all Deposit and Withdrawals done in month of
„May‟ 2017 from table TRANSACT
(iii) To display first date of transaction (DOT) from table TRANSACT for Account having
ANO as 102
(iv) To display ANO, ANAME, AMOUNT and DOT of those persons from ACCOUNT and
TRANSACT table who have done transaction less than or equal to 3000
(v) SELECT ANO, ANAME FROM ACCOUNT
WHERE ADDRESS NOT IN ('CHENNAI', 'BANGALORE');
(vi) SELECT DISTINCT ANO FROM TRANSACT
(vii) SELECT ANO, COUNT(*), MIN(AMOUNT) FROM TRANSACT
GROUP BY ANO HAVING COUNT(*)> 1
(viii) SELECT COUNT(*), SUM(AMOUNT) FROM TRANSACT
WHERE DOT <= '2017-10-01'
32 Consider the following tables EMP and SALGRADE, write the query for (i) to (vi) and output
for (vii) to (x)
TABLE: EMPLOYEE
ECODE NAME DESIG SGRADE DOJ DOB
101 Vikrant Executive S03 2003-03-23 1980-01-13
102 Ravi Head-IT S02 2010-02-12 1987-07-22
103 John Cena Receptionist S03 2009-06-24 1983-02-24
105 Azhar Ansari GM S02 2009-08-11 1984-03-03
108 Priyam Sen CEO S01 2004-12-29 1982-01-19
TABLE: SALGRADE
SGRADE SALARY HRA
S01 56000 18000
S02 32000 12000
S03 24000 8000
(i) To display details of all employee in descending order of their DOJ
(ii) To display NAME AND DESIG of those employees whose sgrade is either „S02‟ or
„S03‟
(iii) To display NAME, DESIG, SGRADE of those employee who joined in the year 2009
(iv) To display all SGRADE, ANNUAL_SALARY from table SALGRADE [where
ANNUAL_SALARY = SALARY*12]
(v) To display number of employee working in each SALGRADE from table EMPLOYEE
(vi) To display NAME, DESIG, SALARY, HRA from tables EMPLOYEE and SALGRADE
where SALARY is less than 50000
(vii) Select MIN(DOJ), MAX(DOB) from employee;
(viii) Select SGrade,Salary+HRA from SalGrade where Sgrade=‟S02‟
(ix) Select count(distinct sgrade) from employee
(x) Select sum(salary), avg(salary) from salgrade
33
(i) To display details of all Trains which starts from New Delhi
(ii) To display PNR, PNAME, GENDER and AGE of all passengers whose AGE is below
50
(iii) To display total numbers of MALE and FEMALE passengers
(iv) To display records of all passengers travelling in trains whose TNO is 12015
(v) SELECT MAX(TRAVELDATE),MIN(TRAVELDATE) FROM PASSENGERS WHERE
GENDER=‟FEMALE‟;
(vi) SELECT END, COUNT(*) FROM TRAINS GROUP BY END HAVING COUNT(*)>1;
(vii) SELECT DISTINCT TRAVELDATE FROM PASSENGERS;
(viii) SELECT TNAME, PNAME FROM TRAINS T, PASSENGERS P WHERE T.TNO=P.TNO
AND AGE BETWEEN 50 AND 60
34 Consider the table SHOPPE and ACCESSORIES, write the query for (i) to (v) and output for
(vi) to (x)
(i) To display Name and Price of all the Accessories in descending order of their Price
(ii) To display Id and Sname of all the Shoppe location in „Nehru Place‟
(iii) To display Name, Minimum and Maximum Price of each Name from ACCESSORIES
table
(iv) To display Name, Price of all Accessories and their respective SName from table SHOPPE
and ACCESSORIES where Price is 5000 or more.
(v) To display all details of accessories where name contains word „Board‟;
(vi) SELECT DISTINCT NAME FROM ACCESSORIES WHERE PRICE>5000;
(vii) SELECT AREA,COUNT(*) FROM SHOPPE GROUP BY AREA;
(viii) SELECT AVG(PRICE), MAX(PRICE) FROM ACCESSORIES WHERE PRICE>=10000;
(ix) SELECT NAME, PRICE*.05 DISCOUNT FROM ACCESSORIES WHERE ID IN („S02‟,‟S03‟)
(x) SELECT * FROM SHOPPE S, ACCESSORIES A WHERE S.ID = A.ID AND PRICE>=10000;
35 a) In a database there are two tables : Write MYSQL queries for (i) to (iii)
Table : Item
ICode IName Price Color VCode
S001 Mobile Phones 30000 Silver P01
S002 Refrigerator 20000 Cherry P02
S003 TV 45000 Black P03
S004 Washing Machine 12000 White P04
S005 Air Conditioner 50000 White P05
Table : Vendor
VCode VName
P01 Rahul
P02 Mukesh
P03 Rohan
P04 Kapil
(i) To display ICode, IName and VName of all the vendors, who manufacture “Refrigerator”.
(ii) To display IName, ICode, VName and price of all the products whose price >=23000
(iii) To display Vname and IName manufactured by vendor whose code is “P04”.
b) What will be the output of the following-
1. Select Round(1449.58,-2);
2. Select Round(7.5789,3);
3. Select Substr(“ Hello Rahul”,3,8);
4. Select Dayofmonth(“2020-10-24”);
36 In a database there are two tables : Write MYSQL queries for (i) to (vi)
Table : Doctors
DocID DocName Department NoofOpdDays
101 J K Mishra Ortho 3
102 Mahesh tripathi ENT 4
103 Ravi Kumar Neuro 5
104 Mukesh Jain Physio 3
Table : Patients
PatNo PatName Department DocId
1 Payal ENT 102
2 Naveen Ortho 101
3 Rakesh Neuro 103
4 Atul Physio 104
(i) To display PatNo, PatName and corresponding DocName for each patient.
(ii) To display the list of all doctors whose NoofOpdDays are more than 3
(iii) To display DocName, Department,PatName and DocId from both the tables where DocID
is either 101 or 103
(iv) To display total no of different departments from Patients table.
37 Given the Table “BANK” with records, Give the output of given queries –
NAME
SACHIN
RAMESH
DINESH
VIKAASH
RAJU
AMRITESH
i. Select * from BANK where Name Like „%ES%‟;
ii. Select * from BANK where Name Like „ _____ SH‟
38 Rajesh a database developer at StoreIndia wants to search the record of those employees whose
name starts from „R‟ and they have not allotted any project, for this he has written the
following query-
Select * from Employee where Name = ‘R%’ and Project=Null;
But the query is not producing the correct output. Rewrite the query after correcting the
errors
39 Considering the Visitor table data, write the query for (i) to (iv) and output for (v) to (viii)
(i) Write a query to display VisitorName, Coming From details of Female Visitors with
Amount Paid more than 3000
(ii) Write a query to display all coming from location uniquely
(iii) Write a query to insert the following values-
7, „Shilpa‟,‟F‟,‟Lucknow‟,3000
(iv) Write a query to display all details of visitors in order of their AmountPaid from
highest to lowest
(v) Select VisitorName from Visitor where Gender=‟M‟;
(vi) Select AmountPaid+200 from Visitor where VisitorID=6;
(vii) Select Sum(AmountPaid) from Visitor where comingFrom=‟Kanpur‟;
(viii) Select Count(VisitorName) from Visitor where AmountPaid is NULL;
40 Write a MySQL query to create the given table (MEMBER)
Column name Datatype Size
ID Char 6
Name Varchar 30
Fee Int 10
DOJ Date
41 What is the Difference between ALTER Table command and UPDATE command?
42 (i) Sanjay was deleting the record of empno=1234, but at the time of execution of command he
forgot to add condition empno=1234, what will be the effect of delete command in this case?
(ii) Sameer is executing the query to fetch the records of employee who are getting salary
between 4000 to 8000, he executed the query as -
Select * from employee where salary between 4000 to 8000;
But he is not getting the correct output, Rewrite the correct query.
43 Write MYSQL command to see the list of tables in current database
44 Sunil decides to delete a PhoneNo column from a MySQL Table (student) after insert the data
into the table. Write the command to delete that particular column in student table.
45 A table Employee contains 5 Rows and 4 Columns and another table PROJECT contains 5
Rows and 3 Columns. How many rows and columns will be there if we obtain Cartesian
product of these two tables?
46 Ranjeet created a table named student, He wants to see those students whose name ending
with p. He wrote a query- SELECT * FROM student WHERE name=”p%”;
But the query is not producing the desired output, Help Ranjeet to run the query by removing
the errors from the query and rewriting it.
47 Consider the following EMPLOYEE table write MYSQL command for (i) to (iv) and Outputs for
(v) to (viii)