Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 获取字符串的第一个字母,忽略;";_Sql_String_Sql Server 2008 - Fatal编程技术网

Sql 获取字符串的第一个字母,忽略;";

Sql 获取字符串的第一个字母,忽略;";,sql,string,sql-server-2008,Sql,String,Sql Server 2008,我正试图得到一个以某个字母开头的书名列表。但是,我需要忽略标题开头的“the”。例如,当我查找以“a”开头的标题时,这个查询应该同时返回“阿拉莫”和“美国历史” 我该怎么做 试试这个查询 select titles from tablename where titles like 'a%' or titles like 'the a%' 编辑 select titles from tablename where REPLACE(titles,'the ','') like 'a%' 使用 在

我正试图得到一个以某个字母开头的书名列表。但是,我需要忽略标题开头的“the”。例如,当我查找以“a”开头的标题时,这个查询应该同时返回“阿拉莫”和“美国历史”


我该怎么做

试试这个查询

select titles
from tablename
where titles like 'a%'
or titles like 'the a%'
编辑

select titles
from tablename
where REPLACE(titles,'the ','') like 'a%'
使用


在您的查询中,或使用模式。

SQL不太好,但您始终可以梳理每个标题,如果第一个字母是“the”,则忽略它并检查标题中下一个单词的第一个字母。问题是,它不适用于字母“t”@GordonLinoff我想知道你想说什么。你能解释一下吗。你会在字母“T”上匹配像“阿拉莫”这样的标题。我认为OP不需要这种匹配。我们可以使用LOWER()和
SQL Serversensitive@dmr您还可以使用
wherereplace(标题,'the','')如'abc%'
... where title like 'a%' or title like 'the a%'
WHERE CASE WHEN SUBSTR(title, 1, 4) = 'the ' THEN SUBSTR(title, 5) ELSE title END LIKE '...'