gpt4 book ai didi

sql - 如何在 MS SQL WHERE IN 中删除(选择多列)

转载 作者:行者123 更新时间:2023-12-01 14:41:30 25 4
gpt4 key购买 nike

我有一张表,可以称之为“Cluster”,它与第二张表 Element 相关。

簇:

Id Group Ele1 Ele2 Ele3
1 1 1 2 3
2 1 4 NULL 9
3 2 5 8 7

元素
Id Name
1 'A'
2 'b'
3 'c'
4 'd'
5 'z'
6 'j'
7 't'
8 'r'
9 'e'

现在我必须删除一个集群
DELETE FROM Cluster
WHERE Cluster.Group= 1

但在我从 Cluster 中删除行之前我需要从 Element 中删除所有相关的行
DELETE FROM Element
WHERE Id IN (SELECT Ele1 Ele2 Ele3
FROM Cluster
WHERE Cluster.Group= 1)

但是这个查询不起作用所以我想念什么?

最佳答案

尝试这个:

DELETE FROM Element
WHERE Id IN (SELECT Ele1
FROM Cluster
WHERE Cluster.[Group] = 1
And Ele1 Is Not NULL

Union

SELECT Ele2
FROM Cluster
WHERE Cluster.[Group] = 1
And Ele2 Is Not NULL

Union

SELECT Ele3
FROM Cluster
WHERE Cluster.[Group] = 1
And Ele3 Is Not NULL
)

关于sql - 如何在 MS SQL WHERE IN 中删除(选择多列),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16735100/

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