BottledTurtles BottledTurtles - 5 months ago 9
MySQL Question

Applying HAVING clause condition depending on a column value

I want to get some records from a table:

HAVING COUNT(*) < n.dailyshow


n.dailyshow
is a number or letter (like
u
)

When
n.dailyshow = 'u'
, it means unlimited, and the
Having Count(*) < n.dailyshow
must be removed or something by
IF
, and when it's a number let the command stay.

Answer

Something like this should work:

having if(n.dailyshow = 'u', true, (count(*) < n.dailyshow))

or

having n.dailyshow = 'u' or (count(*) < n.dailyshow)