oracle:
每月最新一条:
SELECT * FROM (select data_time,meter_id,TT_CREDIT,RE_CREDIT,DATA_STR,min(data_time) over(partition by TO_Char(data_time,‘YYYY-MM‘)) as "atime" from WATER_DATA where 1=1
and meter_id like ‘1111111111%‘
) x where data_time="atime"
每月最后一条:
SELECT * FROM (select data_time,meter_id,TT_CREDIT,RE_CREDIT,DATA_STR,max(data_time) over(partition by TO_Char(data_time,‘YYYY-MM‘)) as "atime" from WATER_DATA where 1=1
and meter_id like ‘1111111111%‘
) x where data_time="atime"
sql:
select FD3d0,FCreateDate,FM3m0
from (select FD3d0,FCreateDate,FM3m0 ,row_number() over (partition by FD3d0 order by FCreateDate) as rn
from TUpdateself where FCreateDate between ‘" fromdate "‘ and DATEADD(DAY,1,‘" fromdate "‘)) t where rn<=1