You are on page 1of 14

Questions

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

(i) To list the BookTitle of FND type.


(ii) To display a report listing BookTitle, Type and Price in descending order of price.
(iii) To count the number of BookTitle, Who have FND type.
(iv) To insert a new row in the table LIBRARY.
7, „Windows 8 Basics‟, „FND‟,‟McGraw‟, 7,150.
(v) SELECT AVG(Price) FROM LIBRARY WHERE Type = „FND‟;
(vi) SELECT COUNT(DISTINCT Type) FROM LIBRARY;
9. Consider the table STUDENT given below. Write commands in MySQL for (i) to (iv) and output
for (v) to (vii). (HOTS) TABLE STUDENT

(i) To list the StudentName of Science Stream.


(ii) To display a report listing StudentName, Class and Stream in ascending order of StudentName.
(iii) To count the number of students to Science Stream.
(iv) To insert a new row in the table STUDENT.
7, „Simran Kaur‟,‟X!l‟, „Commerce‟, 86, „A2‟
(v) SELECT AVG(AggMarks) FROM STUDENT WHERE Stream=„Science‟;
(vi) SELECT COUNT (DISTINCT Stream) FROM STUDENT;
(vii) SELECT MIN(AggMarks) FROM STUDENT;

10. Consider the table PRODUCT given below. Write commands in MySQL for (i) to (iv) and output
for (v) to (vii). TABLE PRODUCT

(i) To list the ProductName where BrandName is Maharaja.


(ii) To display a report ProductName and BrandName and Price in descending order of price.
(iii) To count the number of ProductName.
(iv) To insert a new row in the table PRODUCT.
6, „Gas Stove‟,‟Maharaja‟,7, 6150
(v) SELECT AVG(Price) FROM PRODUCT WHERE BrandName = „Maharaja‟;
(vi) SELECT COUNT (DISTINCT BrandName) FROM PRODUCT;
(vii) SELECT MAX(Price) FROM PRODUCT;
11. Consider the table SPORTS given below. Write commands in MySQL for (i) to (iv) and output
for (v) to (vii).TABLE SPORTS

(i) To list the Name of the students whose Game is Cricket.


(ii) To display a report listing Name, Game and Grade in ascending order of name.
(iii) To count the number of students.
(iv) To insert a new row in the table SPORTS.
7, „Rishabh‟, 9, „Cricket‟, „A‟
(v) SELECT Name, Game FROM SPORTS WHERE Name LIKE „k%„,
(vi) SELECT COUNT (DISTINCT Game) FROM SPORTS;
(vii) SELECT Name, Game, Grade FROM SPORTS WHERE Grade = *B';

12. Consider the table INTERIORS given below. Write commands in MySQL for (i) to (iv) and
output for (v) to (vii).TABLE INTERIORS

(i) To list the ItemName whose Type is Office Table.


(ii) To display a report listing ItemName, Type and Price in descending order of Price.
(iii) To count the number of ItemName.
(iv) To insert a new row in the table INTERIORS.
7, „Comfort Zone‟,‟Double Bed‟,‟23/03/2011′, 15000
(v) SELECT ItemName, Type FROM INTERIORS WHERE ItemName LIKE „R%‟;
(vi) SELECT COUNT (DISTINCT Type) FROM INTERIORS;
(vii) SELECT ItemName, Type FROM INTERIORS WHERE DateofStock>„15/ll/2010‟;
13. Consider the table STUDENTS given below. Write commands in MySQL for (i) to (iv) and
output for (v) to (vii).TABLE STUDENTS

(i) To list the StudentName whose Class is IX.


(ii) To display a report listing StudentName, Class and Score in descending order of Score.
(iii) To count the number of Students.
(iv) To insert a new row in the table STUDENTS.
7, „Divya Prakash‟, „Science‟, 355, „C‟;
(v) SELECT StudentName, Stream FROM STUDENTS WHERE Score >380;
(vi) SELECT COUNT (DISTINCT Stream) FROM STUDENTS;
(vii) SELECT StudentName, Class FROM STUDENTS WHERE Grade = „A‟;

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:

(i) SELECT Name FROM EXAM


WHERE Division=„FIRST‟
ORDER BY Name;
(ii) SELECT Name, Subject, Sti pend*12 FROM EXAM;
(iii) SELECT COUNT!*)
FROM EXAM
WHERE Subject =„Accounts‟ OR
Subject = „ Informatics‟;
(iv) INSERT INTO EXAM VALUES
(6, „Mohan‟,500, „English‟, 73, „SECOND‟);
7. Answer:
(i) SELECT Doc_Name,Date_0f_join FROM DOCTOR
WHERE Department =„Oncology‟;
(ii) SELECT Doc_Name, Salary FROM DOCTOR
ORDER BY Salary DESC;
(iii) SELECT Doc_Name, Salary FROM DOCTOR
WHERE Gender = „F‟AND Salary > 50000;
(iv) SELECT Department, SUM(Salary) FROM DOCTOR GROUP BY Department;

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‟);

You might also like