table与table自己对比,不存在比自己小的时间则为时间最大的那条。
SQL server:
select * from table t1
where not exists(select 1 from table t2
where t1.no=t2.no and t1.name=t2.name
and convert(char(10),t1.add_time,120) = convert(char(10),t2.add_time,120)
and t2.add_time>t1.add_time)
其中sql server中截取时间的方法:
使用convert函数:
select convert(char(10),GetDate(),120) as date (得到的时间为:2018-12-12)
其中函数中的第3个参数就是用来设置日期类型数据的显示样式的。
例:
100 mm dd yyyy
101 mm/dd/yyyy
102 yyyy.mm.dd
103 dd/mm/yyyy
106 dd mm yyyy
108 hh:mi:ss(时间)
111 yyyy/mm/dd
112 yyyymmdd
120 yyyy-mm-dd