![](/img/trans.png)
[英]How to SELECT a field without the first n characters and the last m characters?
[英]How to select titles that are like the first n characters of a string?
这是一个例子
有一些动漫的标题:
|_title_|
|My hero Academia|
|My hero Academia Season 2|
|My hero Academia Season 3|
|My hero Academia Season 4|
我想选择包含第一条记录的前10个字符的标题,因此在此示例中为“我的英雄学院”
重要的是它必须是前N个字符,例如10、15、20。 因此,在SELECT title FROM tablename WHERE title LIKE "%My hero Academia%"
这样的SELECT title FROM tablename WHERE title LIKE "%My hero Academia%"
不是我要的解决方案。
另外:这只是一个例子,还有许多其他标题,我并不总是知道前10个字符是什么。 因此,我也不能简单地在WHERE title LIKE
子句中输入“我的英雄学院”的前10个字符。
我的意思是这样的:
SELECT title FROM table_name WHERE title LIKE the first 10 characters of a given string
有没有办法用SQL做到这一点? 预先感谢您的帮助!
对于部分固定值的字符串过滤,可以使用like 'yourstring%'
这样的运算符,例如:
SELECT title
FROM your_table
WHERE title LIKE 'thefirst10%'
或使用类似substr或left的字符串功能
SELECT title
FROM your_table
WHERE left(title,10) = 'thefirst10'
SELECT title
FROM your_table
WHERE substr(title,1,10) = 'thefirst10'
像这样输入10个字符:
WHERE title LIKE 'aaaaaaaaaa%'
WHERE SUBSTRING(title, 1, n) = 'aaaaaaaaa'
尝试这个:
SELECT title FROM table_name WHERE title like "data structure%"
SELECT title FROM TABLE_NAME WHERE title LIKE '%' + substring('AAA' , 0 ,2)
substring函数的第一个参数代表您的字符串,第二个开始索引和第三个结束索引。您可以根据需要更改结束索引。
使用通配符(%):
SELECT title FROM table_name WHERE title LIKE "1234567890%"
这可以帮助您为我的postgray11赞一下。 ithink它将为您的mysql hwlp
select * from t1 where title LIKE CONCAT((select * from t1 LIMIT 1),'%');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.