如何更改此 SELECT 使其成为用于删除的标准?
SELECT COUNT(empid), empid, status, deptid from tableA
GROUP BY empid, status, deptid HAVING status is null and deptid = 5
如何更改此 SELECT 使其成为用于删除的标准?
SELECT COUNT(empid), empid, status, deptid from tableA
GROUP BY empid, status, deptid HAVING status is null and deptid = 5
你想删除什么?
如果只是在 deptId 5 中记录具有 NULL 状态的记录,则使用
WHERE status is NULL and DeptID = 5
不是很清楚,如果你正在寻找更多...
我猜,用 GROUP BY 删除可能不起作用。
您可以尝试以下方法,看看它是否有效。
DELETE
FROM tableA
WHERE status is null AND deptid=5
DELETE FROM tableA
WHERE status is null AND deptid = 5
Delete from tableA a,
(SELECT COUNT(empid) as count, empid, status, deptid from tableA
GROUP BY empid, status, deptid HAVING status is null and deptid = 5) as b
where a.empid = b.empid
and a.status = b.status
and a.deptid = b.deptid
and b.count > 5
像这样的东西会是你正在寻找的吗?它将删除属于计数> 5的组的所有记录
否则,您实际上并没有从 group by 中删除值,并且可以使用简单的 delete;
Delete from tableA
where status is null
and deptid = 5