LOCATE()函数如何与MySQL WHERE子句一起使用?
当我们将LOCATE()函数与MySQLWHERE子句一起使用时,我们需要将子字符串作为第一个参数,并将表的列名作为第二个参数,以及比较运算符。以下是使用“学生”表进行演示的示例-
示例
假设我们在“学生”表中具有以下值-
mysql> Select * from Student; +------+---------+---------+-----------+ | Id | Name | Address | Subject | +------+---------+---------+-----------+ | 1 | Gaurav | Delhi | Computers | | 2 | Aarav | Mumbai | History | | 15 | Harshit | Delhi | Commerce | | 20 | Gaurav | Jaipur | Computers | | 21 | Yashraj | NULL | Math | +------+---------+---------+-----------+ 5 rows in set (0.02 sec)
现在,以下查询显示了我们如何LOCATE()在WHEREcaluse中使用函数
mysql> Select Name, LOCATE('av',name)As Result from student where LOCATE('av',Name) > 0;
+--------+--------+
| Name | Result |
+--------+--------+
| Gaurav | 5 |
| Aarav | 4 |
| Gaurav | 5 |
+--------+--------+
3 rows in set (0.00 sec)
mysql> select name, LOCATE('av',name)As Result from student where LOCATE('av',Name)=0 ;
+---------+--------+
| name | Result |
+---------+--------+
| Harshit | 0 |
| Yashraj | 0 |
+---------+--------+
2 rows in set (0.00 sec)热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短