我运行命令select * from victims where fname like '%a%' or address like '%194%';
,我得到了这个
+----+---------+---------+---------+--------+--------------------+--------------------+------+
| id | fname | mname | lname | gender | address | email | card |
+----+---------+---------+---------+--------+--------------------+--------------------+------+
| 1 | Ryan | Anthony | O'Keefe | M | 194 lou Lane | ryan@songoda.com | 2543 |
| 3 | Beau | Jacob | Diddly | M | 21 fake cr | elmo@q.com | 6264 |
| 4 | Anthony | Quinn | Jims | M | 34 lol lane | chicks@hotmail.com | 3456 |
+----+---------+---------+---------+--------+--------------------+--------------------+------+
对于那个结果我只希望显示数字1,因为这是唯一同时包含名字中的a和地址中的194的人。有人可以指出我做错了吗?
答案 0 :(得分:1)
select * from victims where fname like '%a%' or address like '%194%';
应该是
select * from victims where fname like '%a%' AND address like '%194%';
如果您希望名字以A
开头,您也可以从前面取模数select * from victims where fname like 'a%' AND address like '194%';