将字段*1或者+0可以将字符串字段按数值排序
如:
select * from table where 1 order by id*1 desc;
或者
select * from table where 1 order by id+0 desc;
ps:求最大值亦然
本文介绍了一种在SQL查询中对字符串类型的字段进行数值排序的方法,即通过在字段后使用*1或+0的方式实现从大到小排序,同时也适用于求取最大值的场景。
将字段*1或者+0可以将字符串字段按数值排序
如:
select * from table where 1 order by id*1 desc;
或者
select * from table where 1 order by id+0 desc;
ps:求最大值亦然
2万+

被折叠的 条评论
为什么被折叠?