2017-02-09 300 views
0

這裏的其他行是我的代碼選擇一列是一個重複的,也選擇不重複

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 
+3

您的代碼無關,與你的樣本數據。 –

+0

最初我有重複,所以我寫了代碼,現在它只返回一個1 – Percy

+0

你會怎麼做? @GordonLinoff – Percy

回答

0

嘗試使用group by子句

SELECT OrderNumber 
    FROM AccountOrder 
    group by OrderNumber 

所以如果我的表有下列順序號

1 
2 
2 
3 

查詢將返回

1 
2 
3