简体   繁体   English

Oracle SQL - 仅在下个月 1 日之前的最后一次读数

[英]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.需要提取最后 6 个完整月/年 (Month_Year),仅在下个月 1 日之前进行最后一次读数。

在此处输入图像描述

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.每个数字的最新读数以及格式为 Mon-YYYY 的当前日期。

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

相关问题 SQL 日期场景,用于在 1 日获取上个月的数据,然后在上个月下降 - SQL date scenario for getting previous month's data to-date on the 1st of month, then drop last month SQL本月1日到月底 - SQL 1st of the month to the end of the month Oracle SQL从月底-16日和15日-1日检索数据 - Oracle SQL Retrieve Data From End of Month - 16th And 15th - 1st "在oracle sql中获取从第1个月到当前日期的数据" - get the data starting from 1st month till current date in oracle sql Oracle SQL 除了确定的天数外,计算到最接近的每月 1 日 - Oracle SQL calculating to the nearest 1st of the month IN ADDITION to a determined amount of days 如何在sql中选择最近5年的每月的1号? - How can I select the 1st of every month for the last 5 years in sql? SQL 查询以在每个月的第一天到最后一天的列中显示每日计数结果 - SQL Query to Display Daily Count Results in Columns from 1st to last day of month 如何在Oracle SQL中的第一个连字符之后和第三个连字符之前提取数据 - How to extract data AFTER 1st hyphen and before 3rd hyphen in Oracle SQL 将iSeries日期设置为下个月1日后将其转换为字符串 - Convert iSeries Date to String after setting it to 1st of next month SQL 仅在第一个 TRUE 条件下返回 - SQL returns only for 1st TRUE condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM