gpt4 book ai didi

mysql - 如何从sql表或sql数据库中导出所有单词

转载 作者:太空宇宙 更新时间:2023-11-03 11:04:20 26 4
gpt4 key购买 nike

假设我们有下表。

UserId | Message-------|-------------1      | Hi, have a nice day2      | Hi, I had a nice day

我需要将所有 { Hi,-have-a-nice-day-I-had } 字分开。有什么办法吗?如果我想从整个数据库表中导出单词怎么办?

类似的结果也不错。

最佳答案

试试这个:在 Sql server 2005 或以上

create table yourtable(RowID int, Layout varchar(200))
INSERT yourtable VALUES (1,'hello,world,welcome,to,tsql')
INSERT yourtable VALUES (2,'welcome,to,stackoverflow')


;WITH SplitSting AS
(
SELECT
RowID,LEFT(Layout,CHARINDEX(',',Layout)-1) AS Part
,RIGHT(Layout,LEN(Layout)-CHARINDEX(',',Layout)) AS Remainder
FROM YourTable
WHERE Layout IS NOT NULL AND CHARINDEX(',',Layout)>0
UNION ALL
SELECT
RowID,LEFT(Remainder,CHARINDEX(',',Remainder)-1)
,RIGHT(Remainder,LEN(Remainder)-CHARINDEX(',',Remainder))
FROM SplitSting
WHERE Remainder IS NOT NULL AND CHARINDEX(',',Remainder)>0
UNION ALL
SELECT
RowID,Remainder,null
FROM SplitSting
WHERE Remainder IS NOT NULL AND CHARINDEX(',',Remainder)=0
)
SELECT part FROM SplitSting ORDER BY RowID

SQLFIDDLE DEMO

关于mysql - 如何从sql表或sql数据库中导出所有单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13117710/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com