select acpsn_num as 人员编码,bvschool as 毕业学校
from hr_hi_person a
left join
(
select , row_number() over(partition by cpsn_num order by dgrduateDate desc) as rowNum from hr_hi_edu
)b
on acpsn_num =bcpsn_num and browNum=1
有时间列就取最大时间列
有自增的id就去最大id
如果是想返回一个记录集,并且有时间列的话可以这么做
select 重复列,时间列,其余列
inner join (select 重复列,max(时间列) as 时间列 from 表 group by 重复列) AS T2
on t1重复列=t2重复列 and t1时间列 =t2时间列
from 表 AS T1
如果数据库也存在对应当前时间的一条数据呢,要不要也要一起取。
假设要的话,oracle的写法是这样子,假如当前时间是current_time, 有数据表TABLE1,字段为data和create_date 可以这样写
select from (select from TABLE1 where create_date > current_time order by create_date ) where rownum = 1
union
select from (select from TABLE1 where create_date < current_time order by create_date desc) where rownum = 1
union
select from TABLE1 where create_date = current_time and rownum = 1
意思就是取得小于目标时间的最大的一条记录和大雨目标时间的最小的一条记录以及等于目标时间的一条记录的结果集。因为oracle没有类似于sql server的limit和top这些函数,只能通过排序来取得最近的记录,如果是sql server简单多了。
如何写SQL从一个表里,获取最近两个月的数据记录
一:如果要插入目标表不存在:
select into 目标表 from 表 where
二:如果要插入目标表已经存在:
insert into 目的表 select from 表 where 条件
三:如果是跨数据库 *** 作的话: 怎么把A数据库的atable表所查询的东西,全部插入到B 数据库的btable表中
select into Bbtable from Aatable where
同样,如果是跨服务器的,也是可以的。
以上就是关于sql语句中怎么去取最近时间的值全部的内容,包括:sql语句中怎么去取最近时间的值、sql中如何取重复的数据取时间最近的一条、SQL 取出时间在当前时间前后最近的两条记录等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)