我有一个名为 remit_bill 的表格,我希望使用以下查询从此表中获取最大日期,但它会继续向我显示错误。在同一个bill_no.i下有几个日期想要获得coll_amt值的最大日期。非常感谢。
SQL> desc remit_bill
Name Null? Type
------------------------------- -------- ----
SC_CD NOT NULL VARCHAR2(2)
RMT_NO NOT NULL VARCHAR2(6)
RMT_DT DATE
BILL_NO NOT NULL VARCHAR2(6)
COLL_AMT NOT NULL NUMBER(10,2)
查询:
select sum(COLL_AMT) FROM REMIT_BILL AS P
WHERE bill_no = '887332' and rmt_dt=(SELECT MAX(rmt_dt) FROM REMIT_BILL AS P2
where P2.bill_no=P.BILL_NO
--GROUP BY COLL_AMT
)
GROUP BY COLL_AMT
错误讯息:
select sum(COLL_AMT) FROM REMIT_BILL AS P
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
SQL>
图片:
答案 0 :(得分:2)
试试这个
select sum(p.COLL_AMT) FROM REMIT_BILL P
WHERE p.bill_no = '887332' and p.rmt_dt=(SELECT MAX(rmt_dt) FROM REMIT_BILL P2
where P2.bill_no=P.BILL_NO
)
GROUP BY p.COLL_AMT