简体   繁体   English

如何使用子查询获取Oracle中的最大日期

[英]How to get the max date in Oracle using a subquery

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. 我有一个名为remit_bill的表,我想使用以下查询从该表中获取最大日期,但它一直向我显示错误。同一bill_no下有多个日期。我想使用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)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM