子查询中的WHERE子句

子查询中的WHERE子句

本文介绍了子查询中的WHERE子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Though I need to have that sub query also limits on ld_relopdrachtgever = '1'
How is that possible with an HAVING statement?

推荐答案

您也可以在子查询中使用WHERE.

You can also use WHERE in sub-query.

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'

这篇关于子查询中的WHERE子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 17:25