以下SQL查询:
select * from er_101
where cd_relnaam IN (
select cd_relnaam
from er_101
group by cd_relnaam
having count(*) > 1)
AND ld_relopdrachtgever = '1'
虽然我需要将该子查询限制在ld_relopdrachtgever = '1'
上
如何通过HAVING语句实现这一点?
答案 0 :(得分:2)
您还可以在子查询中使用WHERE
。
SELECT * FROM er_101
WHERE cd_relnaam IN (
SELECT cd_relnaam
FROM er_101
WHERE ld_relopdrachtgever = '1' <--You can add WHERE clause before GROUP BY
--^^^^^----
GROUP BY cd_relnaam
HAVING COUNT(*) > 1)
AND ld_relopdrachtgever = '1'
答案 1 :(得分:0)