Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.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
sql查询以查找不在其他表中的记录_Sql - Fatal编程技术网

sql查询以查找不在其他表中的记录

sql查询以查找不在其他表中的记录,sql,Sql,我有一个表plist,其中有一列list,其中包含逗号分隔的ID(1,2,3,4)。我想要id不在逗号分隔列表中的成员的记录。最好的方法是将逗号分隔列表拆分为一个表,然后对其进行搜索 以下是拆分字符串的代码: DECLARE @YourTable table (RowID int, Layout varchar(200)) INSERT @YourTable VALUES (1,'1,2,3,4') ;WITH SplitSting AS ( SELECT RowID,

我有一个表
plist
,其中有一列
list
,其中包含逗号分隔的ID(1,2,3,4)。我想要id不在逗号分隔列表中的成员的记录。

最好的方法是将逗号分隔列表拆分为一个表,然后对其进行搜索

以下是拆分字符串的代码:

DECLARE @YourTable table (RowID int, Layout varchar(200))
INSERT @YourTable VALUES (1,'1,2,3,4')

;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 RowID,part FROM SplitSting ORDER BY RowID

哪种关系数据库管理系统?SQL Server、MySQL等。唯一有效的答案应该是“重新设计您的DB模式并阅读有关规范化的内容”,您使用的是哪台DB服务器?