Mysql how to create an if statement within a having to find out if my variable is in between two other values

StackOverflow https://stackoverflow.com/questions/9398881

  •  29-10-2019
  •  | 
  •  

문제

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     |
도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top