MySql numeric string comparison of the pit

1. We do numerical comparison size of the string, they usually think that 10 is greater than 9, but the fact that 10 is the minimum, how to solve this problem, given such a program

2. phenomenon

SELECT
	id,
	type_name AS typeName,
	type_code AS typeCode,
	pcode,
	tag_pic AS tagPic,
	is_del AS isDel 
FROM
	o2o_merchant_type 
ORDER BY
	type_code DESC;
select MAX(t1.type_code) as type_code from o2o_merchant_type as t1;
	

 

 We found a string of 10 smaller than the other values

We found that it is also seeking maximum of 9 instead of 10

3. The solution, in the sort field +0

SELECT
	id,
	type_name AS typeName,
	type_code AS typeCode,
	pcode,
	tag_pic AS tagPic,
	is_del AS isDel 
FROM
	o2o_merchant_type 
ORDER BY
	type_code + 0 DESC 
select MAX(t1.type_code + 0) as type_code from o2o_merchant_type as t1;

 

problem solved

A road called Land of the Dead, a bridge, known as regrettable; a river called Lethe; Sansei Stone River, circle to make the edge.

Willing, waist sword only for the Iraqi people

Cheng, three thousand hair are tied to the king

He, laughing cure my drink

She does not skim Lethe tears

Guess you like

Origin blog.csdn.net/LuckFairyLuckBaby/article/details/93207328