0

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

4

2 回答 2

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'
于 2012-10-26T10:54:07.113 回答
0

请参阅有关查找重复记录的“文章” http://blog.sqlauthority.com/2007/07/11/sql-server-count-duplicate-records-rows/

于 2012-10-26T11:00:44.633 回答