最佳答案
尝试这个查询:
SELECT respond_id, incident_id, pnt_id FROM TBL
WHERE pnt_id IS NOT NULL
UNION
SELECT respond_id, incident_id, pnt_id FROM TBL
WHERE incident_id in (SELECT distinct(incident_id)
FROM TBL
GROUP BY incident_id
HAVING count(id) = 1);
联合的第一部分将获取所有非空的 pnt_ids 第二部分将获取所有可能为空但进入结果的记录。
Union合并两个结果消除重复
关于mysql - SQL:防止数据显示有条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40888649/