【问题标题】:Convert T-SQL stored procedure query to MySQL将 T-SQL 存储过程查询转换为 MySQL
【发布时间】:2021-06-21 21:58:52
【问题描述】:

我正在将查询从 MS SQL Server 转换为 MySQL

我的 SQL Server 查询如下。

SELECT      userId,IndustriesID,value AS ProvIndusID
FROM        #Talent_list
CROSS APPLY STRING_SPLIT(IndustriesID,',') 

我被困在这里将字符串转换为行并交叉应用。

【问题讨论】:

标签: mysql sql database-migration


【解决方案1】:

MySQL 没有返回表的函数。您可以用递归 CTE 替换逻辑:

with recursive cte as (
      select state, cast(null as char(100)) as city, cities, 0 as lev
      from talent_list
      union all
      select state, substring_index(cities, ',', 1),
             substr(cities, length(substring_index(cities, ',', 1)) + 2), lev + 1
      from cte
      where cities <> '' and lev < 5
     )    
select state, city
from cte
where lev > 0;

Here 是一个 dbfiddle。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    • 2011-02-15
    • 1970-01-01
    • 2013-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多