i have the table 'points_level' with :
id | description | level
--------------------------
1 | noob | 0
2 | rookie | 50
3 | The boss | 100
i need to build a function that return the id of the level giving points as integer for example :
select calc_level(12)
result: 1
select calc_level(90)
result: 2
select calc_level(300)
result: 3
select calc_level(100)
result: 3
select calc_level(-50)
result: 1
i need to add some level in the points_level table (in the near future) so i shuldn't calculate the results via some simple "CASE WHEN" i think about a "CASE WHEN" in a for loop, i found some example for SSQL but nothing for MYSQL and i don't know the MYSQL SYNTAX for create this kind of function :(
somebody can help me ?
Thanks