Haadi Owais Haadi Owais - 22 days ago 8
SQL Question

List all the rows that satisfy a condition in mysql

i have done a attendance table with columns as follows:
|usn|name|date|ispresent|

where is present is of boolean datatype.
i want to retrieve all the rows whose attendance is less than 75%.
using avg() function it lists each students avg but how to retrieve the details of students whose avg() is less than a particular value.

I am new to sql and I seriously need help.


Thanks in advance.

Answer

You can use HAVING:

SELECT usn, name, AVG(ispresent) attendance FROM table 
GROUP BY usn, name HAVING attendance < 0.75;
Comments