[Assignments] Simple Queries in SQL — Chapter 12 Assignments (Q/A)

|
Table of Contents

15. Given the following table:
Give the output of following SQL statements:

No.NameStipendStreamAvgMarkGradeClass
1Karan400.00Medical78.5B12B
2Divakar450.00Commerce89.2A11C
3Divya300.00Commerce68.6C12C
4Arun350.00Humanities73.1B12C
5Sabina500.00Nonmedical90.6A11A
6John400.00Medical75.4B12B
7Robert250.00Humanities64.4C11A
8Rubina450.00Nonmedical88.5A12A
9Vikas500.00Nonmedical92.0A12A
10Mohan300.00Commerce67.5C12C
Table : STUDENT

(i) SELECT MIN(AvgMark) FROM STUDENT WHERE AvgMark < 75 ;
(ii) SELECT SUM(Stipend) FROM Student WHERE Grade = ‘B’ ;
(iii) SELECT AVG(Stipend) FROM Student WHERE Class = ’12A’ ;
(iv) SELECT COUNT(DISTINCT) FROM Student ;

MIN(AvgMark)
64.4
SUM(Stipend)
1150.00
AVG(Stipend)
475.00

This error message indicates that there’s a syntax error in your SQL query near the DISTINCT keyword. MySQL is indicating that it expected something after the DISTINCT keyword, such as a column name, but found nothing. That is, you need to specify which column you want to count the distinct values of.

If you want to count the distinct values in all columns, you would have to repeat the COUNT(DISTINCT) for each column or use an asterisk * to count all columns’ distinct values.

The correct syntax would be:

"Spread the light within, illuminate the hearts around you. Sharing is not just an action, but a sacred journey of connecting souls."~ Anonymous

Leave a Reply

Your email address will not be published. Required fields are marked *