mysql - Can't use "HAVING" "OR" "WHERE" together -
i want write query selects rows if last timestamp newer 2 days or there 200 children. trying combine where
having
, this:
... parent.timestamp < date_sub(current_date, interval 2 day_hour) or having count(parentid) > 199 group parent.tid order parent.lastchildid desc limit 200
but gives me syntax error.
how can use or between these 2 conditions?
since having
applies aggregate , where
applies rowset, can't blend them that. instead, use subquery turn having
where
condition on count:
select ... parent parent.timestamp < date_sub(current_date, interval 2 day_hour) or (select count(*) mytable tid = parent.tid) > 199 order parent.lastchildid desc limit 200
Comments
Post a Comment