Mysql - fine tune HAVING -
does have ideas on how solve query?
there table customers , table licenses. each client can have several licenses expiring @ different times, expired , not yet. if want select customers @ to the lowest degree 1 valid license, do:
select * license left bring together client using (customer_id) grouping customer.customer_id having license.expiry > now()
but how customers have expired licenses? if "having license.expiry < now()" it'll find customers expired licenses alright, not exclude customers have valid licenses @ same time. need select customers have expired licenses.
"not having" solve problem, there's no such thing...
any help appreciated.
try query -
select * license left bring together client using (customer_id) grouping customer.customer_id having count(*) > 0 , count(*) = count(if(license.expiry > now(), 1, null))
mysql
No comments:
Post a Comment