我需要SQL Server 2008 R2中的查询

时间:2014-03-03 10:15:25

标签: sql sql-server-2008-r2

我有一个名为Table1的表,其中包含4列。

例如:

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  

3 个答案:

答案 0 :(得分:2)

Select Distinct Field1, Field2 
from Table1

答案 1 :(得分:2)

SELECT DISTINCT Field1,Field2 FROM TABLE_NAME

答案 2 :(得分: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