當我們將INSTR() 函數與MySQL WHERE 子句一起使用時,我們需要提供表格的列名作為第一個參數,提供子字串作為第二個參數以及比較運算符。以下是使用「學生」表進行演示的範例-
假設「學生」表中有以下值-
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)
現在,以下查詢展示如何將INSTR() 函數與WHERE caluse 一起使用-
mysql> select name, INSTR(Name,'av')As Result from student where INSTR(Name,'av') > 0; +--------+--------+ | name | Result | +--------+--------+ | Gaurav | 5 | | Aarav | 4 | | Gaurav | 5 | +--------+--------+ 3 rows in set (0.00 sec) mysql> select name, INSTR(Name,'av')As Result from student where INSTR(Name,'av') = 0 ; +---------+--------+ | name | Result | +---------+--------+ | Harshit | 0 | | Yashraj | 0 | +---------+--------+ 2 rows in set (0.01 sec)
以上是我們如何將 MySQL INSTR() 函數與 WHERE 子句一起使用?的詳細內容。更多資訊請關注PHP中文網其他相關文章!