2

我知道要选择以“a”作为列中第二个字母的记录,我们编写以下查询:-

Select * from table where column1 like '_a%';

为了选择列中第三个字母为“a”的记录,我们编写:-

Select * from table where column1 like '__a%';

现在我想选择column1包含“_”(下划线)作为第二个字符的记录。例如,我想选择column1像 A_John、B_John、A_Jai 等的记录。在这种情况下我可以使用什么转义字符。我怎样才能做到这一点?请帮忙。

4

3 回答 3

7

采用:

 Select * from books where title like '\_\_a%';

首先是两个下划线和

Select * from books where title like '\_a%';

首先是单个下划线和

于 2012-05-21T07:17:14.040 回答
1

'\' 字符用于转义:

Select * from table where column1 like '_\_a%';
于 2012-05-21T07:16:36.907 回答
0

\ 是 MySQL 中的转义字符。采用:

Select * from table where column1 like '_\_%';

于 2012-05-21T07:16:03.400 回答