如何从mysql数据库字段中检索最后4个字符?

时间:2022-09-25 15:47:19

In order to be able to simulate substr from PHP and mysql, I want to do something like

为了能够从PHP和mysql模拟substr,我想做类似的事情

select * from table where last_four_chars(field) = '.png'

4 个解决方案

#1


35  

The docs have an example directly relevant to this.

文档中有一个与此直接相关的示例。

select * from table where SUBSTRING(field, -4) = '.png'

#2


13  

With RIGHT function :

具有RIGHT功能:

SELECT RIGHT('abcdefg', 3);
-- efg

You can achieve the same result with SUBSTRING :

您可以使用SUBSTRING获得相同的结果:

SELECT SUBSTRING('abcdefg', -3);
-- efg

#3


5  

This Fast query:

这个快速查询:

Select * from table where picName like '%.png'

#4


2  

SELECT * FROM table WHERE SUBSTRING( field, -4 ) = '.png'

#1


35  

The docs have an example directly relevant to this.

文档中有一个与此直接相关的示例。

select * from table where SUBSTRING(field, -4) = '.png'

#2


13  

With RIGHT function :

具有RIGHT功能:

SELECT RIGHT('abcdefg', 3);
-- efg

You can achieve the same result with SUBSTRING :

您可以使用SUBSTRING获得相同的结果:

SELECT SUBSTRING('abcdefg', -3);
-- efg

#3


5  

This Fast query:

这个快速查询:

Select * from table where picName like '%.png'

#4


2  

SELECT * FROM table WHERE SUBSTRING( field, -4 ) = '.png'