oracle where 子句中的聚合函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5898507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:35:51  来源:igfitidea点击:

Aggregate function in where clause

sqloracle

提问by Tom

I have two tables: TITLE and BACKGROUND

我有两个表:TITLE 和 Background

BACKGROUND has a foreign key into TITLE so I'm trying to write a query that will return any TITLE rows that have more than one matching BACKGROUND.

背景有一个进入 TITLE 的外键,所以我正在尝试编写一个查询,该查询将返回具有多个匹配背景的任何 TITLE 行。

SELECT T.ID
  FROM TITLE T, BACKGROUND B
 WHERE T.ID = B.TITLE_ID
   AND /* there are multiple matching background rows */

回答by mevdiven

select t.id
  from title t
 where exists (select * 
                 from background b
                where b.title_id = t.id
                having count(*) > 1 )

回答by Rajesh Chamarthi

Have you tried.....

你有没有尝试过.....

select T.ID from (
    SELECT T.ID,B.TITLE_ID, count(*)
      FROM TITLE T, BACKGROUND B
      WHERE T.ID = B.TITLE_ID
      group by T.ID,B.TITLE_ID
      having count(*) > 1
)