我有一张表如下......
--------------------------------------------------------------
TRANS_TYPE_CD | Member_ID | POINT_ACCOUNT_TYPE | TRANS_DTM
--------------------------------------------------------------
Debit | 1702 | 10 | 2018-12-04
Credit | 1702 | 10 | 2018-12-04
Debit | 1702 | 10 | 2018-12-04
Debit | 1702 | 10 | 2018-12-04
Debit | 1702 | 10 | 2018-12-04
------------------------------------------------------------
现在我希望从这个表中选择包含行数的数据。 为此,我正在使用这个SQL ...
select rowNumber, trans_dtm, lower(trans_type_cd) as trans_type_cd
from (
select pttrans.trans_dtm, pttrans.trans_type_cd
, row_number() over (partition by trans_dtm order by trans_dtm desc ) as rowNumber
from (
select * from point_trans
where member_id = 1702
and point_account_type = 10
and (point_type_cd is null or point_type_cd not in ('Hold' ,'RolledBack','Rolledback'))
and trans_dtm between to_date('2014-06-30', 'yyyy-mm-dd') and to_date('2018-12-04', 'yyyy-mm-dd')
) pttrans
fetch first 300 rows only
)
where rowNumber between 1 and 10
order by trans_dtm desc;
但是在输出中,作为rowNumber我总是得到1 ......这就是“1和10之间的rowNumber”子句无法正常工作的原因......
我得到的结果......
rowNumber | TRANS_DTM | TRANS_TYPE_CD
-----------------------------------------
1 | 2018-12-04 | debit
1 | 2018-12-04 | debit
1 | 2018-12-04 | debit
1 | 2018-12-04 | credit
-----------------------------------------
任何人都可以帮助我使用正确的SQL。我的要求只是获取行号并根据参数过滤掉行。
我正在使用AWS Oracle RDS ....
提前致谢...