Mysql 查找并选择字符串的一部分
我有一个描述字段,如:Mysql 查找并选择字符串的一部分,mysql,sql,sql-server-2008,Mysql,Sql,Sql Server 2008,我有一个描述字段,如: Item ----- 37A38/PE10 520-37Art/PE9 5674/PE01 我只想选择/PE之前的部分,如下所示: 37A38 520-37Art 5674 MySQL SQL Server select substring(item,1,charindex('/PE',item)-1) from table 在MSSQL中,您可以使用以下代码: 您可以使用left和charindex进行查询,如:- select left(item,ch
Item
-----
37A38/PE10
520-37Art/PE9
5674/PE01
我只想选择/PE之前的部分,如下所示:
37A38
520-37Art
5674
MySQL
SQL Server
select substring(item,1,charindex('/PE',item)-1) from table
在MSSQL中,您可以使用以下代码: 您可以使用left和charindex进行查询,如:-
select left(item,charindex('/',item)) as Item
from table_name
选择leftitem、charindex“/”、Item是否可能与mysql或sqlserver重复?
SELECT LEFT(Item, CHARINDEX('/PE',Item)-1) from table WHERE Item LIKE '%/PE%'
select left(item,charindex('/',item)) as Item
from table_name