MYSQL Questions For Group by Clause
MYSQL Questions For Group by Clause
1. What is the purpose of GROUP BY clause in MySQL? How is it different from ORDER BY clause?
Question 1.
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‟.
Question2.
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.
Question 3
Consider the table LIBRARY given below. Write commands in MySQL for (i) to (iv) and output for
(v) to (vii).
TABLE LIBRARY
Question4.
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‟)
Question 5
Consider the table PRODUCT given below. Write commands in MySQL for (i) to (iv) and output for
(v) to (vii).
TABLE PRODUCT
(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';
Question7.
Consider the table INTERIORS given below. Write commands in MySQL for (i) to (iv) and output
for (v) to (vii).
TABLE INTERIORS
(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’;
Question 8
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‟;
Question 9
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). (HOTS)
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‟.
Question 10
Consider the table SUPPLIER given below. Write commands in MySQL for (i) to (iv) and output for
(v) to (vii). (i)
TABLE SUPPLIER
(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)