Skip to content
Advertisement

How I can get limit_exceded value if value is less than or greater than in “limit_exceded” column i would get 1 else 0 in mysql

database table_img for better understanding Pardon me for weak English writing

my sql query that i am getting value,low_value,high_value and limit_exceded_. issue is in limit_exceded to not get correct values, it shows all 0.

I want to get int 1 in front of those values whose value is less than 40 or greater than 180. Also it would it be appreciated if extract max and min from this list and count limit_exceded values

expected result is set value 1 where values is 900,9 and 1 etc

Advertisement

Answer

issue is in limit_exceded to not get correct values, it shows all 0

I suspect the issue is the types. The way the data lines up in the image and the use of strings in the WHERE clause suggest that the values are strings not numbers. A simply way to convert is to use + 0:

Notes:

  • Table aliases make the query easier to write and to read.
  • Unnecessary backticks just make the query harder to write and to read.
  • In MySQL, you don’t need the CASE expression — you can just use the boolean expression.

That said, you should fix the data, not the query. If the values are numbers, store them as numbers, not string.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement