select year(datetime) 年,
month(datetime) 月,
last_day(datetime) 月最后一天
from table
group by year(datetime),month(datetime)
having year(datetime) = trunc(sysdate,'y’)
select t1.*
from text_table t1
where t1.t_date in
(select max(t.t_date)
from text_table t
where to_char(t.t_date, 'y‘) = to_char(sysdate, 'y‘)
group by to_date(t.t_date, 'ymm'))
无语不能重复输入y,所以上面代买都只写一个y
欢迎大家互相交流学习!
笨办法,先计算出一天每个月每天的数据,然后根据月分组对天进行开窗排序,取最后一个。