sql—删除多列值为null或零值的行

yquaqz18  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(1047)

我有一个问题,这个sql,它说这是一个语法问题附近删除,但无法找到它,请帮助
这是我第一次尝试使用delete函数,所以不知道怎么做

SELECT 
DE.ContactID AS ContactID,
DE.[First Name] AS [First Name],
DE.[Last Name] AS [Last Name],
DE.Email AS Email,

CASE WHEN bu.ContactId IS NULL 
               THEN '0'
               ELSE '1'
END AS Business,

CASE WHEN des.ContactId IS NULL 
               THEN '0'
               ELSE '1'
END AS Design,

CASE WHEN he.ContactId IS NULL 
               THEN '0'
               ELSE '1'
END AS Health,

CASE WHEN ho.ContactId IS NULL 
               THEN '0'
               ELSE '1'
END AS Hospitality,

DELETE 
FROM [IOW Registered - All workshops]
WHERE (Business IS NULL OR Business = 0) 
                AND (Design IS NULL OR Design = 0) 
                AND (Health IS NULL OR Health = 0)
                AND (Hospitality IS NULL OR Hospitality = 0)

FROM [Domestic SCH] DE 
LEFT JOIN Business bu ON DE.ContactId = bu.ContactId
LEFT JOIN Design des ON DE.ContactId = des.ContactId
LEFT JOIN Health he ON DE.ContactId = he.ContactId
LEFT JOIN Hospo ho ON DE.ContactId = ho.ContactId
dffbzjpn

dffbzjpn1#

首先编写select语句以获取要删除的所有记录。运行它并确保它工作正常。
然后使上面的select语句只选择要删除的记录的id。例如:

Select domesticTableID from domesticTable where Design IS NULL or Design = 0

然后在delete语句中,将上面的select语句放在where子句中:

Delete from domensticTable where domesticTableID in (Select domesticTableID from domesticTable where Design IS NULL or Design = 0)

如果您不能完全弄清楚,请发布select语句,该语句返回要删除的记录。

相关问题