简体   繁体   English

如何在不希望字符串中第二个字母的情况下为mysql写一条select语句?

[英]How can I write a select statement for mysql where I only do not want the second letter in the string?

I am trying to write a select statement for mysql where I want to exclude all strings that contain an 'a' as the second letter. 我正在尝试为mysql写一条select语句,其中要排除所有包含'a'作为第二个字母的字符串。 Here is my select statement so far. 到目前为止,这是我的选择语句。 It works for the most part, but some still slip through for reason I do not understand. 它在大多数情况下都有效,但是由于我不明白的原因,仍然有些漏掉了。

Select title, replacement_cost, rating from film where title not like "-a%" and replacement_cost = 19.99

Use the underscore as wildcard for a single character: 使用下划线作为单个字符的通配符:

Select title, replacement_cost, rating 
from film 
where title not like "_a%" 
and replacement_cost = 19.99

SQL Wildcards SQL通配符

or with SUBSTR 或使用SUBSTR

Select title, replacement_cost, rating 
from film 
where SUBSTR(title, 2, 1) <> 'a'
and replacement_cost = 19.99

请尝试这个

Select title, replacement_cost, rating from film where substr(title,2,1)!='a' and replacement_cost = 19.99

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用MySQL查询进行自然排序,我想要排序的东西以字母开头? - How do I do natural sorting with a MySQL query where the thing I want sort by starts with a letter? 如何使用选择查询在mysql中编写更新语句? - How Can i write update statement in mysql with select query? Mysql:如何编写选择,其中id不在另一个表中 - Mysql: How do I write select where ids are not in another table 如何编写具有2个条件的SELECT IF语句? - How do I write a SELECT IF statement with 2 conditionals? 我如何在 codeigniter 中编写这个 MYSQL 语句? - How do i write this MYSQL statement in codeigniter? 我可以为 1 个 SELECT (mysql) 做多个 WHERE 吗? - Can I do multiple WHERE for 1 SELECT (mysql)? 我怎样才能在mysql中编写IF语句 - how can I write IF statement in mysql 我如何选择带有联合语句的mysql数据,该数据与每个选择语句匹配,即将AND运算符与UNION结合在一起? - How can I select mysql data with a union statement where the data matches each select statement, i.e. combine the AND operator with UNION? 如何在MySQL中为字符串的每个字母分配一个变量? - How do I assign a variable to each letter of a string in MySQL? MySQL:如何将字符串“ 1,2,3,4”转换为(1,2,3,4),以便能够在“ where X in()”语句中使用它 - MySQL: how can i convert a string '1,2,3,4' to a (1,2,3,4) so i'll be able to use it in a 'where X in ()' statement
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM