How do you compare big numbers in MySQL?

< H2 > as mentioned in the title, how do very large numbers in MySQL (saved with varchar type) compare in size? < / H2 >

We have tried that the numbers converted by the functions cast () and convert () all have maximum values, but there is a problem in directly comparing the size of strings, so is there any good solution?

attachment: the following method is also available on the network
SELECT ("4294967295000000000000000000000000000000000000000000000000" + 0) >
       ("4294967295000000000000000000000000000000000000000000000000" + 1);

but the result is 0 anyway. So it still doesn"t work!

Mar.24,2021

`SELECT ('429496729500000000000000000000000000000000000000000000000000000000000) >

   ('4294967295000000000000000000000000000000000000000000000000' + 1);`
   0

the test I did in mysql version 5.6.35:
1. First run only the following statement:

SELECT ('4294967295000000000000000000000000000000000000000000000000' + 0);

the result is 4.294967295e+45 trillion

2, then run the statement that compares the two numbers:

select if(('4294967295000000000000000000000000000000000000000000000000' + 0) > ('4294967295000000000000000000000000000000000000000000000000' + 1), 0, 1)

the result is 1

combining the above test results, it shows that the numbers represented by the two strings can be compared.


We have not experienced this technique, so we put it into practice, which is not the same as you. It is suspected that you are old in mysql. How many generations are you? Laugh:-D, I haven't tried this operation either, so I tried it, and the result is different from yours. It seems that your mysql version is a problem, how many versions are yours! Thank you. You can get the result by comparing it directly. And you say mysql returns 0, because mysql false returns 0, there will be no false return, forget it!

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3fc4d-2bd12.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3fc4d-2bd12.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?