Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.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
Mysql 查找并选择字符串的一部分_Mysql_Sql_Sql Server 2008 - Fatal编程技术网

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