Practical MYSQL
Practical MYSQL
1
Table : Store
StoreId Name Location City NoOfEmployees DateOpened SalesAmount
S101 Planet fashion Karol Bagh Delhi 7 2015-10-16 300000
S102 Trends Nehru Mumbai 11 2015-08-09 400000
16. Observe the given table named “Loan” carefully and predict the output of the following queries:
i. SELECT concat(left(file_no,2), right(cust_name,2)) AS “ID” from loan where Bank='ICUCI Ltd.';
ii. select round(loan_amt-loan_amt*10/100) As "Discounted Payment" from loan where loan_amt>700000;
2
(Aggregate Functions)
1. Consider the table TEACHER given below. Write commands in SQL for (1) and output for (2) to (5)
i. To count the number of teachers in English department. ii. SELECT MAX(Hiredate) FROM Teacher;
iii. SELECT DISTINCT(category) FROM teacher; iv. SELECT COUNT(*) FROM TEACHER WHERE Category = "PGT"
v. SELECT Gender,AVG(Salary) FROM TEACHER group by Gender;
10. Consider the following table named "GYM" with details about fitness items being sold in the store. Write output
(i) SELECT COUNT (DISTINCT (BRANDNAME) ) FROM GYM; (ii) SELECT MAX (PRICE ) FROM GYM;
11.
Consider the following table named 'SBOP" with details of account holders. Write output.
3
13. Consider the table FLIGHT given below. Write output.
14. What will be the output of the following queries on the basis of Employee
table:
20. Kunal has entered the following SQL command on Table ‘STUDENT’ that has TotalMarks as one of the columns.
SELECT COUNT (*) FROM STUDENT;
The output displayed is 20.
4
Then, Kunal enters the following command :
SELECT COUNT (*) FROM STUDENT WHERE TotalMarks <100;
The output displayed is 15.
Then, Kunal enters the following command :
SELECT COUNT (*) FROM STUDENT WHERE TotalMarks >= 100;
He predicts the output of the above query as 5. Do you agree with Kunal ? Give reason for your answer.
21. Consider the table given below :
Write command for (i) and output for (ii)
(i) To display Area along with number of Salespersons working in
that area.
(ii) SELECT Area, COUNT (*) FROM Salesperson GROUP BY Area
HAVING COUNT (*) > 1;
6. What is the purpose of ORDER BY clause in MySql ? How is it different from GROUP BY clause?
5
7. Consider the Table SHOPPE given below. Write command in MySql
for (i) and output for (ii) to (iii).
8. Consider the table ‘PERSONS’ given below. Write commands in SQL for (i) to (iv) and write output for (i) to (iii).
9. There is a column HOBBY in a Table CONTACTS. The following two statements are giving different outputs. What
may be the possible reason ?
SELECT COUNT(*) FROM CONTACTS;
SELECT COUNT(HOBBY)FROM CONTACTS;