选择一个重复的行,并选择不重复的其他行

时间:2017-02-09 15:08:58

标签: sql sql-server

这是我的代码

select i.RefNo,i.Premium,i.Description from (select d.Description,c.IsActiveRecord,c.RefNo,c.MovementID, c.Premium,ROW_NUMBER() 
over(partition by c.premium order by c.refno) n from lif_mgm_t_contract c 
inner join SDT_LJG_T_MovementDescription d with (nolock) on c.MovementID = d.MovementID ) i
   where i.n = 1 and i.MovementID <> 0 

所以例如

a
a
b

我希望查询返回

a
b and not just a hope this makes sense --only a beginner 

1 个答案:

答案 0 :(得分:0)

尝试使用group by子句

SELECT OrderNumber
  FROM AccountOrder
  group by OrderNumber

所以如果我的表有以下订单号

1
2
2
3

查询将返回

1
2
3