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

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -