having可以实现where where不能实现having
查询借阅书籍超过3本的人
where :
select reader.reader_id, reader.c
from (
select count(borrow.reader_id) as c , borrow.reader_id
from borrow
group by borrow.reader_id ) as reader
where reader.c >= 3
having:
select count(reader_id) as num, reader_id
from borrow
group by reader_id
having count(reader_id) >= 3
having效率狗屎, 但是逻辑简单, where效率勉强, 但是写法复杂度高了