页次: 1
如果要从小到大排列, “1”, “11”, “2”, “22”
不会出现 “1", "11", "2", "22"
二应该是 "1", "2", "11", "22"
通过 +, 1
select * from tb_001 order by x * 1; select * from tb_001 order by x + 0;
示例代码
mysql> create table tb_001 ( x varchar(20) ); Query OK, 0 rows affected (0.04 sec) mysql> insert into tb_001 (x) values ('11'), ('1') , ('2'), ('22'); Query OK, 4 rows affected (0.01 sec) Enregistrements: 4 Doublons: 0 Avertissements: 0 mysql> select * from tb_001 ; +------+ | x | +------+ | 11 | | 1 | | 2 | | 22 | +------+ 4 rows in set (0.00 sec) mysql> select * from tb_001 order by x; +------+ | x | +------+ | 1 | | 11 | | 2 | | 22 | +------+ 4 rows in set (0.00 sec) mysql> select * from tb_001 order by x * 1; +------+ | x | +------+ | 1 | | 2 | | 11 | | 22 | +------+ 4 rows in set (0.00 sec) mysql> select * from tb_001 order by x + 0; +------+ | x | +------+
ipbbs.net
离线
mysql> select "5" = 5; +---------+ | "5" = 5 | +---------+ | 1 | +---------+ 1 row in set (0.02 sec) mysql> select "5" = "5"; +-----------+ | "5" = "5" | +-----------+ | 1 | +-----------+ 1 row in set (0.00 sec)
如果是相加 , 对字符串解析,而不是转化。
mysql> select "5" + "sdf5@"; +---------------+ | "5" + "sdf5@" | +---------------+ | 5 | +---------------+ 1 row in set, 1 warning (0.00 sec) mysql> select "5" + "5@"; +------------+ | "5" + "5@" | +------------+ | 10 | +------------+ 1 row in set, 1 warning (0.00 sec) mysql> select "5" + "5.1ds@"; +----------------+ | "5" + "5.1ds@" | +----------------+ | 10.1 | +----------------+ 1 row in set, 1 warning (0.00 sec)
ipbbs.net
离线
页次: 1