Basically it’s a type error.
Min and Max act alphabetically in strings.
To test, change the query for this:
SELECT MIN(0 + users_licensed) FROM prt_license
or this:
SELECT MAX(0 + users_licensed) FROM prt_license
So you will be forcing a numerical interpretation. But this is only for testing, ideally you should work with the right type column.
Another good test (just like learning) would be to put the columns with a padding of zeros on the left, and see that there by "coincidence" the strings behave like numbers in the sort question:
010
050
100
120
etc..
To convert the column
Back up before such changes. A query below converts the table column to the correct type, causing your SELECT
original work numerically.
ALTER TABLE prt_license MODIFY users_licensed INTEGER;
After the conversion, this is enough:
SELECT MAX(users_licensed) FROM prt_license;
What type of column?
– Jéf Bueno
Yeah, now that I’m fixing it, she’s a varchar... she’s automatically generated by the system
– gabrielfalieri
The result is correct. 5 is greater than 1
– Bacco
Only it has fields with 400 users, this would be the biggest
– gabrielfalieri
4 is between 1 and 5, ordering by strings would be 100, 3, 400, 50, 9, etc
– Bacco