数据库字段如下:name,tel,time张 133 2010-2-2
李 133 2010-2-3
黄 134 2010-2-4
张 135 2010-2-5
王 135 2010-2-6现想显示结果如下,并将tel字段里的重复内容去除
name,tel,time王 135 2010-2-6
黄 134 2010-2-4
张 133 2010-2-2
李 133 2010-2-3
黄 134 2010-2-4
张 135 2010-2-5
王 135 2010-2-6现想显示结果如下,并将tel字段里的重复内容去除
name,tel,time王 135 2010-2-6
黄 134 2010-2-4
张 133 2010-2-2
select t.* from tb t where time = (select max(time) from tb where tel = t.tel) order by t.time descselect t.* from tb t where not exists (select 1 from tb where tel = t.tel and time > t.time) order by t.time desc
(select distinct tel from tb) a
cross apply
(select top(1) * from tb where tel = a.tel order by [time] desc/*asc*/) b
order by b.[time] desc
李 133 2011-2-3
黄 134 2012-2-4
张 135 2010-2-5
王 135 2011-2-6现想显示结果如下,并将time字段里的重复内容去除
name,tel,time张 133 2010-2-2
李 133 2011-2-3
黄 134 2012-2-4