Haadi Owais Haadi Owais - 1 year ago 72
SQL Question

List all the rows that satisfy a condition in mysql

i have done a attendance table with columns as follows:

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 Source

You can use HAVING:

SELECT usn, name, AVG(ispresent) attendance FROM table 
GROUP BY usn, name HAVING attendance < 0.75;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download