第1个回答 2018-03-01
CREATE TABLE #tmp
(id int PRIMARY KEY,
A VARCHAR(5),
B VARCHAR(5),
C VARCHAR(5),
D VARCHAR(5),
E VARCHAR(5));
INSERT INTO #tmp
SELECT 1, 'A1','B1','C1','D1','E1'
UNION ALL
SELECT 2,'A1','B1','C2','D2','E2'
UNION ALL
SELECT 3,'A2','B2','C3','D3','E3'
UNION ALL
SELECT 4,'A2','B2','C4','D4','E4'
UNION ALL
SELECT 5,'A3','B3','C5','D5','E5'
UNION ALL
SELECT 6,'A3','B3','C6','D6','E6'
SELECT MAX(id),A,B,MAX(C),MAX(D),MAX(E) FROM #tmp
GROUP BY A,B;
DROP TABLE #tmp;
希望能帮到您~