-1

如果您有此列表的数据:

nvarchar  int    int    nvarchar   nvarchar
Line      start  end    typ        color
-------------------------------------------
T11       1      null   cookie     Blue
T11       null   10     cookie     Blue
T11       null   null   cookie     Blue
T11       null   null   cookie     Blue
T2        20     null   computer   Red
T2        null   null   computer   Red
T2        null   52     computer   Red
T3        null   null   dark       black
T3        52     null   dark       black
T3        null   10     dark       black

请求的结果应该是:

Line      start  end    typ        color
-------------------------------------------
T11       1      10     cookie     Blue
T2        20     52     computer   Red
T3        52     10     dark       black

我应该如何在 SQL Server 2012 中做到这一点?

4

1 回答 1

2

我想这就是你所要求的。显然将 tablename 替换为您的表的名称。

SELECT t.line, MIN(t.START), MAX(t.END), t.typ, t.color
FROM dbo.tablename t
GROUP BY t.line, t.typ,  t.color
于 2013-02-22T11:31:03.610 回答