Professional Documents
Culture Documents
1. Consider the following table named SBOP with details of account holders. Write commands of
MySql for (i) to (iv) and output for (v) to (vii).TABLE SBOP
(i) To display Accountno, Name and DateOfopen of account holders having transactions more than 8.
(ii) To display all information of account holders whose transaction value is not mentioned.
(iii) To add another column Address with datatype and size as VARCHAR(25).
(iv) To display the month day with reference to DateOfopen for all the account holders.
(v) SELECT COUNT (*) FROM SBOP;
(vi) SELECT Name, Balance FROM SBOP WHERE Name LIKE “%i”;
(vii) SELECT ROUND (Balance,-3) FROM SBOP
WHERE Accountno="SB-5” ;
2. Consider the following table named EXAM with details of marks. Write command of MySQL for
(i) to (iv) and output for (v) to (vii).
Table EXAM
(i) To display all information of the students of humanities in descending order of percentage.
(ii) To display Adno, Name, Percentage and Stream of those students whose name is less than 6
characters long.
(iii) To add another column Bus_Fees with datatype and size as Decimal(8,2).
(iv) To increase percentage by 2% of all the Humanities students. (All India 2014)
(v) SELECT COUNT(*) FROM EXAM;
(vi) SELECT SName, Percentage FROM EXAM WHERE Name LIKE “N%”;
(vii) SELECT ROUND (Percentage ,0) FROM EXAM
WHERE Adno=“R005”;
3. Consider the table SUPPLIER given below. Write commands in MySQL for (i) to (iv) and output
for (v) to (vii). (i)
TABLE SUPPLIER
(i)To display product name whose name start with B in order by price.
(ii) To display scode,pname and city of supplier where quantity is less than 150.
(iii) To count distinct City in the table.
(iv) To insert a new row in the table SUPPLIER.
110, “Bournvita”,‟ ABC‟, 170, „Delhi‟, 40.00 (Delhi 2012)
(v) SELECT Pname FROM SUPPLIER WHERE Supname IN ('Bread', 'Maggt');
(vi) SELECT COUNTCDISTINCT City) FROM SUPPLIER;
(vii) SELECT MAX(Price) FROM SUPPLIER
WHERE City = „Kol kata‟;
4. Consider the table SHOPEE given below. Write commands in MySQL for (i) to (iv) and output
for (v) to (vii). TABLE SHOPEE
(i) To display names of the product, whose name starts with „C‟ in ascending order of Price.
(ii) To display code, product name and City of the products whose quantity is less than 100.
(iii) To count distinct Company in the table.
(iv) To insert a new row in the table SHOPEE.
110, „Pizza‟, „Papa Jones‟, 120, „Kolkata‟, 50.00 (All India 2012)
(v) SELECT Pname FROM SHOPEE WHERE Pname IN („Jam‟, „Coffee‟);
(vi) SELECT COUNT(DISTINCT City) FROM SHOPEE;
(vii) SELECT MAX(Qty) FROM SHOPEE WHERE City = „Mumbai‟
5. Consider the table PERSONS given below. Write commands in SQL for (i) to (iv) and write
output for
(v) to (viii).TABLE PERSONS
(i) Display the SurName, FirstName and City of people residing in Udhamwara city.
(ii) Display the Person IDs (PID), Cities and Pincode of persons in descending order of Pincode.
(iii) Display the FirstName and City of all the females getting Basic salaries above 40000.
(iv) Display FirstName and BasicSalaries of all the persons whose first name start with „G‟. (Delhi
2012c)
(v) SELECT SurName FROM PERSONS WHERE BasicSalary>= 50000;
(vi) SELECT SUM (BasicSalary) FROM PERSONS WHERE Gender = „F‟;
(vii) SELECT Gender, MIN (BasicSalary) FROM PERSONS GROUP BY Gender;
(viii) SELECT Gender, COUNT (*) FROM PERSONS
GROUP BY Gender;
6. Consider the table EXAM given below. Write commands in MySQL for (i) to (iv) and output for
(v) to (vii).
TABLE EXAM
(i) To list the Names of those students, who have obtained Division as FIRST in ascending order of
Name.
(ii) To display a report listing Name, Subject and Annual Stipend received assuming that the Stipend
column has monthly Stipend.
(iii) To count the number of students, who have either Accounts or Informatics as Subject.
(iv) To insert a new row in the table EXAM.
6, „Mohan‟, 500, „English‟, 73, „SECOND‟ (HOTS; Delhi 2011)
(v) SELECT AVG(Stipend) FROM EXAM WHERE Division = „THIRD‟;
(vi) SELECT COUNT (DISTINCT Subject) FROM EXAM;
(vii) SELECT MIN(Average) FROM EXAM WHERE Subject = „English‟;
7. Consider the table DOCTOR given below. Write commands in SQL for (i) to (iv) and output for
(v) to (vii).
TABLE DOCTOR
(i) Display the names and dates of joining of doctors of Oncology department.
(ii) Display the names and salaries of doctors in descending order of salaries.
(iii) Display the names and salaries of all the female‟s doctors who are getting salary above $ 50000.
(iv) Display names of each department along with total salary being given to doctors of that
department. (Delhi 2011)
(v) SELECT Department FROM DOCTOR WHERE Salary >= 55000;
(vi) SELECT SUM (Salary) FROM DOCTOR WHERE Department = „Surgery‟;
(vii) SELECT Doc_Name FROM DOCTOR WHERE Doc_Name LIKE ‟J ‟%;
8. Consider the table LIBRARY given below. Write commands in MySQL for (i) to (iv) and output
for (v) to (vii).TABLE LIBRARY
10. Consider the table PRODUCT given below. Write commands in MySQL for (i) to (iv) and output
for (v) to (vii). TABLE PRODUCT
12. Consider the table INTERIORS given below. Write commands in MySQL for (i) to (iv) and
output for (v) to (vii).TABLE INTERIORS
14. Consider the following table FITNESS with details about fitness products being sold in the store.
Write command of SQL for (i) to (iv) and output for (v).TABLE FITNESS
(i) To display the names of all the products with price more than 20000.
(ii) To display the names of all products by the manufacturer „Aone‟.
(iii) To change the price data of all the products by applying 25% discount reduction.
(iv) To add a new row for product with the details: „P7‟, „Vibro Exerciser‟, 28000, „Aone‟.
(v) SELECT * FROM FITNESS
WHERE MANUFACTURER LIKE ‟%e‟;
Answers
1. Answer:
(i) SELECT Account no, Name, DateOfopen FROM SBOP
WHERE Transaction > 8:
(ii) SELECT * FROM SBOP
WHERE Transaction IS NULL;
(iii) ALTER TABLE SBOP
ADD Address VARCHAR(25);
(iv) SELECT DAY0FM0NTH(DateOfopen), Name
FROM SBOP:
2. Answer:
(i) SELECT * FROM EXAM
WHERE Stream = „Humanities‟
ORDER BY Percentage DESC;
(ii) SELECT Adno, SName, Percentage, Stream FROM EXAM
WHERE LENGTH(SName)<6;
(iii) ALTER TABLE EXAM
ADD Bus_Fees DECIMALS, 2) ;
(iv) UPDATE EXAM
SET Percentage = Percentage + 2
WHERE Stream = „Humanities‟;
vi) The given query will result in an error as there is no column named Name in table EXAM.
3. Answer:
(i) SELECT Pname FROM SUPPLIER
WHERE Pname LIKE „B%‟
ORDER BY Price;
(ii) SELECT Scode, Pname, City
FROM SUPPLIER
WHERE Qty < 150;
(iii) SELECT COUNT(DISTINCT City)
FROM SUPPLIER;
(iv) INSERT INTO SUPPLIER VALUES (110,„Bournvita‟, „ABC‟, 170, „Delhi‟, 40.00);
4. Answer:
(i) SELECT Pname
FROM SH0PEE WHERE Pname LIKE „C%‟
ORDER BY Price;
(ii) SELECT Scode, Pname, City FROM SHOPEE
WHERE Qty < 100;
(iii) SELECT COUNT (DISTINCT Surname)
FROM SHOPEE;
(iv) INSERT INTO SHOPEE VALUES (110, „ Pi zza‟, „ Papa Jones ‟ , 120, „Kolkata‟, 50.00);
5. Answer:
(i) SELECT SurName, FirstName, City
FROM PERSONS
WHERE City = „Udhamwara‟;
(ii) SELECT PID, City. PinCode FROM PERSONS
ORDER BY Pincode DESC;
(iii) SELECT FirstName, City FROM PERSONS
WHERE Gender = „F‟ AND
BasicSalary > 40000;
(iv) SELECT FirstName, BasicSalary FROM PERSONS
WHERE FirstName LIKE „G%‟;
6. Answer:
8. Answer:
(i) SELECT BookTitle FROM LIBRARY WHERE Type = „FND‟;
(ii) SELECT BookTitle, Type, Price FROM LIBRARY
ORDER BY Price DESC;
(iii) SELECT COUNT(*)
FROM LIBRARY WHERE Type = 'FND';
(iv) INSERT INTO LIBRARY VALUES (7, „Windows 8 Basics', „ FND‟ , „McGraw‟,7,150);
9. Answer:
(i) SELECT StudentName FROM STUDENT
WHERE Stream = „Science‟;
(ii) SELECT StudentName, Class, Stream FROM STUDENT
ORDER BY StudentName;
(iii) SELECT COUNT(*)
FROM STUDENT
WHERE Stream = „Science‟;
(iv) INSERT INTO STUDENT
VALUES (7, „Simran Kaur‟.'XII‟, „Commerce‟, 86, „A2 ‟);
10. Answer:
(i) SELECT ProductName FROM PRODUCT
WHERE BrandName = „Maharaja‟;
(ii) SELECT ProductName, BrandName, Pri ce
FROM PRODUCT ORDER BY Price DESC;
(iii) SELECT COUNT (*)
FROM PRODUCT;
(iv) INSERT INTO PRODUCT VALUES (6,„Gas Stove‟, „Maharaja‟,7, 6150);
11. Answer:
(i) SELECT Name FROM SPORTS
WHERE Game = „Cricket‟;
(ii) SELECT Name, Game,Grade . FROM SPORTS
ORDER BY Name;
(iii) SELECT COUNT (*)
FROM SPORTS;
(iv) INSERT INTO SPORTS VALUES (7, „Rishabh‟, 9, „Cricket‟, „A‟);
12. Answer:
(i) SELECT ItemName FROM INTERIORS
WHERE Type = „Office Table‟;
(ii) SELECT ItemName, Type, Price FROM INTERIORS ORDER BY Price DESC;
(iii) SELECT COUNT(*)
FROM INTERIORS;
(iv) INSERT INTO INTERIORS VALUES (7, „Comfort Zone‟, „Double Bed‟,„23/03/2011‟,15000);
13. Answer:
(i) SELECT StudentName
FROM STUDENTS
WHERE Class = IX‟ ;
(ii) SELECT StudentName, Class, Score
FROM STUDENTS
ORDER BY Score DESC;
(iii) SELECT COUNT(* )
FROM STUDENTS;
(iv) INSERT INTO STUDENTS VALUES (7, „Divya Prakash‟, „Science‟, 355, „C‟);
14. Answer:
(i) SELECT PNAME
FROM FITNESS WHERE PRICE > 20000;
(ii) SELECT PNAME FROM FITNESS WHERE MANUFACTURERSAone';
(iii) UPDATE FITNESS SET PRICE=PRICE-PRICE* 25/100;
(iv) INSERT INTO FITNESS VALUES („P7‟, „Vibro Exerciser‟, 28000, „Aone‟);