以下 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 语句怎么可能?
以下 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 语句怎么可能?
您也可以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'