简体   繁体   中英

Oracle SQL - only last reading before the 1st of next month

Number field is the key but it can be modified several times a month (or not all all). Need to pull for last 6 complete month/year (Month_Year), only last reading before the 1st of next month.

在此处输入图像描述

So you want something like this?

select number, to_char(sysdate, 'Mon-YYYY') as month_year,
       max(reading) keep (dense_rank first order by modified_date_time desc) as reading
from t
group by number;

The most recent reading for each number along with the current date formatted as Mon-YYYY.

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.

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