2014-03-03 61 views
0

我有一個名爲Table1的表,它包含4列。我需要SQL Server 2008 R2中的查詢

對於前:

id Field1 Field2 fIELD3 
1 A  1  R1 
2 A  1  R2 
3 B  3  R21 
4 A  1  R3 
5 B  3  R44 

我需要一個查詢,讓我這個結果

Field1 Field2 
A  1 
B  3 
+0

是場2取決於FIELD1? – user2864740

回答

2
Select Distinct Field1, Field2 
from Table1 
+0

好男人,如果我有field3和field4 ...但我只是想區分field1和2 – Ibra

2
SELECT DISTINCT Field1,Field2 FROM TABLE_NAME 
0

方法1:

SELECT Field1, Field2 
from Table1 
Group BY Field1, Field2 

方法2:

Select Distinct Field1, Field2 
From Table1 

方法3:

Select Field1, Field2 
From 
    (
     Select Field1, Field2,Row_NUmber() Over(Partition by Field1, Field2 Order By Field1) AS RN 
    ) AS T 
Where RN = 1