将 T-SQL 存储过程查询转换为 MySQL
Convert T-SQL stored procedure query to MySQL
我正在将查询从 MS SQL 服务器转换为 MySQL
我的 SQL 服务器查询如下。
SELECT userId,IndustriesID,value AS ProvIndusID
FROM #Talent_list
CROSS APPLY STRING_SPLIT(IndustriesID,',')
我被困在这里将字符串转换为行并交叉应用。
MySQL 没有 return 表的函数。您可以用递归 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 是一个 db<>fiddle.
我正在将查询从 MS SQL 服务器转换为 MySQL
我的 SQL 服务器查询如下。
SELECT userId,IndustriesID,value AS ProvIndusID
FROM #Talent_list
CROSS APPLY STRING_SPLIT(IndustriesID,',')
我被困在这里将字符串转换为行并交叉应用。
MySQL 没有 return 表的函数。您可以用递归 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 是一个 db<>fiddle.