CREATE TABLE `test` (
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT 'id',
`type` tinyint(4) NOT NULL COMMENT '类型',
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT '名称',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
INSERT INTO `test`(`id`, `type`, `name`) VALUES (1, 0, '名称0');
INSERT INTO `test`(`id`, `type`, `name`) VALUES (2, 1, '名称1');
INSERT INTO `test`(`id`, `type`, `name`) VALUES (3, 2, '名称2');
INSERT INTO `test`(`id`, `type`, `name`) VALUES (4, 0, '名称4');
select * from test where type = 'type ';
select * from test where type = 0;
id | type | name |
---|---|---|
1 | 0 | 名称0 |
4 | 0 | 名称4 |
MySQL在数字上下文中静默地将字符串转换为数字。
通过将前导数字字符转换为数字来实现。如果没有数字,则值为0.
因此,这相当于‘type' = 0,因为type 第一位为字母,没有数据,假设你的SQL是
select * from test where type = '1type';
那么结果为:2 1 名称1