当我运行此查询时:
select prnt_c_fam_id as PRNT_C_FAM_ID3, min(ptel_d_redet_due) as Date_DUE
from ptel t
where ptel_d_redet_due > (select max(rest_d)
from rest
where prnt_c_fam_id = t.prnt_c_fam_id
and rest_c in ('RS'))
group by prnt_c_fam_id
order by prnt_c_fam_id
查询成功返回。当我在它周围添加括号时:
(select prnt_c_fam_id as PRNT_C_FAM_ID3, min(ptel_d_redet_due) as Date_DUE
from ptel t
where ptel_d_redet_due > (select max(rest_d)
from rest
where prnt_c_fam_id = t.prnt_c_fam_id
and rest_c in ('RS'))
group by prnt_c_fam_id
order by prnt_c_fam_id)
我得到了ORA00907:错过了正确的Paranthesis错误。谁知道为什么? (注意:此查询需要括号,因为它成为较大查询的from子句中的子查询。其他子查询在单独运行时使用和不使用括号。)
答案 0 :(得分:1)
如果您将它用作子查询,请删除order by子句。子查询应如下所示。
(
select prnt_c_fam_id as PRNT_C_FAM_ID3, min(ptel_d_redet_due) as Date_DUE
from ptel t
where ptel_d_redet_due > (select max(rest_d)
from rest
where prnt_c_fam_id = t.prnt_c_fam_id
and rest_c in ('RS'))
group by prnt_c_fam_id
)