我有一张带有评分结果的表格。一些结果具有相同的分数。我想按 TrackingNumber 对所有结果进行分组,然后选择得分最低的记录。如果组内有平局(组中的最低分数出现多次)我不想选择它。这是帮助解释的tsql:
CREATE TABLE Dupe
(
Id INT NOT NULL IDENTITY( 1, 1 ) PRIMARY KEY,
TrackingNumber INT NOT NULL,
Name VARCHAR(50),
Score INT NOT NULL
)
GO
INSERT INTO dbo.Dupe ( TrackingNumber, Name, Score )VALUES ( 1, 'Name1', 1 )
INSERT INTO dbo.Dupe ( TrackingNumber, Name, Score )VALUES ( 1, 'Name1', 3 )
INSERT INTO dbo.Dupe ( TrackingNumber, Name, Score )VALUES ( 1, 'Name1', 3 )
INSERT INTO dbo.Dupe ( TrackingNumber, Name, Score )VALUES ( 1, 'Name1', 5 )
INSERT INTO dbo.Dupe ( TrackingNumber, Name, Score )VALUES ( 2, 'Name2', 1 )
INSERT INTO dbo.Dupe ( TrackingNumber, Name, Score )VALUES ( 2, 'Name2', 4 )
INSERT INTO dbo.Dupe ( TrackingNumber, Name, Score )VALUES ( 2, 'Name2', 9 )
INSERT INTO dbo.Dupe ( TrackingNumber, Name, Score )VALUES ( 4, 'Name4', 11 )
INSERT INTO dbo.Dupe ( TrackingNumber, Name, Score )VALUES ( 4, 'Name4', -55 )
INSERT INTO dbo.Dupe ( TrackingNumber, Name, Score )VALUES ( 4, 'Name4', -55 )
期望的输出:
| ID | TRACKINGNUMBER | NAME | SCORE |
---------------------------------------
| 1 | 1 | Name1 | 1 |
| 4 | 2 | Name2 | 1 |
有人可以指出我如何做到这一点的正确方向吗?