Mysql how to create an if statement within a having to find out if my variable is in between two other values
-
29-10-2019 - |
Question
I'm trying to create a stored procedure like followed
...Having (IF(input_val between 1 and 10, 1,0) AS rank
example
|input_val | rank |
--------------------|
| 1 | 1 |
| 11 | 0 |
| 3 | 1 |
| 22 | 0 |
| 4 | 1 |
| 5 | 1 |
Solution
A HAVING clause normally follows a GROUP BY clause and is used to test the results of an aggregate function. I don't think that's appropriate for what you want here. How about:
...
CASE WHEN input_val BETWEEN 1 AND 10 THEN 1 ELSE 0 END AS rank
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow