i have a table named remit_bill and i would like to get the max date from this table using the following query but it keeps on showing me errors.there are several dates under the same bill_no.i want to get the maximum date with coll_amt value.any help with this would be appreciated.
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)
Query :
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
Error Message :
select sum(COLL_AMT) FROM REMIT_BILL AS P
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
SQL>
Image:
try this
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.