2016-07-19 61 views
0

我在where子句中使用聚合函数时遇到错误。如何在where子句中使用聚合函数

“聚合不应出现在where子句,除非它是一个包含具有子句或选择列表在子查询 ,列 被聚合为外referrence”。

查询:

Select a.*,b.* 
from address a 
join account c on a.acct_no=b.acct_no 
where a.stop_date in (select max(a.stop_date) 
         from address x 
         where x.acct_no=a.acct_no and x.addr_code=a.addr_code) 

请建议如何处理它

+0

哪些DBMS您使用的? –

+0

我试图使用x.stop_date,但它导致了错误的数据。其实我正在将oracle转换为sql。在oracle中它工作正常。 –

+0

“*我正在将Oracle转换为SQL *”没有任何意义。 Oracle ***使用SQL作为查询语言。您已经使用SQL –

回答

0

您应该使用x.stop_date而不是a.stop_date

Select a.*,b.* 
from address a 
join account b on a.acct_no=b.acct_no 
where a.stop_date in (select max(x.stop_date) 
         from address x 
         where x.acct_no=a.acct_no and x.addr_code=a.addr_code) 
相关问题