首页 > 解决方案 > Oracle SQL中奇怪的缺少右括号错误

问题描述

我有这个where子句,当我尝试保存它时,会显示“缺少右括号”错误。代码如下:

where
(
  (a.date is not null 
  and sysdate between b.date and b.date2
  and b.per_id is not null
  group by b.per_id)

or 
  (a.date is null
  and b.per_id is not null
  group by b.per_id)
)

这样做的目的是检查何时a.datenull输出满足的值,sysdate between b.date and b.date2否则何时a.datenot null输出满足的值sysdate not between b.date and b.date2

标签: sqloracle

解决方案


group by是该子句之后where子句。这不是一个条件。

所以你要:

select . . .
from . . .
where (a.date is not null and
       sysdate between b.date and b.date2 and
       b.per_id is not null
      ) or 
      (a.date is null and
       b.per_id is not null 
      )
group by b.per_id

推荐阅读