Greetings! I'm trying to get the top library users, when the user borrowed and returned a book 10 times or more, s/he belongs to the top library users. Here is my sql commant.

SELECT sb.stud_Id, COUNT(sb.stud_Id) >=10 AS total
FROM tbl_studentbook AS sb
LEFT JOIN tbl_student AS s ON s.id = sb.stud_Id
WHERE EXISTS
(
SELECT stud_Id
FROM tbl_studentbook
WHERE sbook_Borrow != '0000-00-00' AND sbook_Return != '0000-00-00'
)
GROUP BY total

My problem is I can't group it by total , error says that 'cant group on total' ..My purpose upon grouping it is that it will show only the id that pass the total value of 10.

Any help? thank you.

swampBoogie
—
2012-03-16T15:03:18Z —
#2

select stud_Id
from tbl_studentbook
where sbook_Return <> '0000-00-00'
group by stud_id
having count(*) > 10

claro
—
2012-03-16T15:13:02Z —
#3

Thak you very much for the quick response sir. I works now.

Mittineague
—
2014-09-23T23:43:17Z —
#4

This topic is now archived. It is frozen and cannot be changed in any way.