当前位置: 代码迷 >> Sql Server >> 关于Group by 自动排序的有关问题
  详细解决方案

关于Group by 自动排序的有关问题

热度:50   发布时间:2016-04-24 10:36:41.0
关于Group by 自动排序的问题
例如现在表中的数据是这样的:
item_no                  item_name              
W2014-01               测试1                     
W2014-01               测试1                     
W2014-03               测试3                     
W2014-02               测试2                        

我希望查询出来是这样的
item_no                  item_name
W2014-01               测试1
W2014-03               测试3
W2014-02               测试2

请问有现在方法解决! 
------解决方案--------------------
按第三个字段排序可行,重复值可以这样处理:
select  item_no ,item_name
from tb a 
where exists (select 1 from (select item_no ,item_name,max(时间列) 时间列 from tb  group by  item_no ,item_name)b
where a.item_no =b.item_no  and a.item_name=b.item_name and a.时间列=b.时间列)
order by 时间列
  相关解决方案