就是一个查询sql,现在要求是查出coupon_no为a,日期最近的一条数据,但金额是两条数据相加的值,也就是金额查询结果为25,目前写出来的sql是这种,得不到想要的结果..这种情况应该要怎么写啊(我这写的有点简化,实际会展示很多列)
数据: coupon_no total_prices accept_date
a 20 2022/04/17
a 5 2022/04/18
select total_prices from (select total_prices,
row_number() OVER(PARTITION BY coupon_no ORDER BY accept_date desc) counts)
from tb) temp where temp.counts = '1'