日期:2014-05-18 浏览次数:20654 次
select * from tb t where col=(select max(col1) from tb where convert(varchar(16),col,120)=convert(varchar(16),t.col,120))
------解决方案--------------------
select * from tb a where not exists (select 1 from tb b where datediff(minute, a.dt, b.dt) = 0 and b.dt < a.dt)
------解决方案--------------------
select a1.* from(
select row_number() over(partition by convert(varchar(100), datetimeObj, 23)+' '+convert(varchar(16),datepart(hh,datetimeObj))+':'+convert(varchar(16),datepart(mi,datetimeObj)) order by datetimeObj asc) as rowindex,* from table1) a1 where rowindex=1
注释:datetimeObj 表内时间字段名 table1 表名
------解决方案--------------------
with cte as ( select '2011-08-03 19:25:27' as v_time union all select '2011-08-03 19:25:32' union all select '2011-08-03 19:25:37' union all select '2011-08-03 19:25:43' union all select '2011-08-03 19:25:48' union all select '2011-08-03 19:25:54' union all select '2011-08-03 19:25:59' union all select '2011-08-03 19:26:04' union all select '2011-08-03 19:26:10' union all select '2011-08-03 19:26:15' union all select '2011-08-03 19:26:20' union all select '2011-08-03 19:26:26' union all select '2011-08-03 19:26:31' union all select '2011-08-03 19:26:37' union all select '2011-08-03 19:26:43' union all select '2011-08-03 19:26:48' union all select '2011-08-03 19:26:53' union all select '2011-08-03 19:26:59' union all select '2011-08-03 19:27:04' union all select '2011-08-03 19:27:09' union all select '2011-08-03 19:27:15' ) , cte2 as ( select v_time, ROW_NUMBER() over(partition by convert(varchar(16),v_time,120) order by v_time desc) as v_rk from cte ) select * from cte2 where v_rk='1'