日期:2014-05-17 浏览次数:20435 次
CREATE TABLE #tab(MB001 VARCHAR(50),MB002 INT,MB003 VARCHAR(50))
INSERT INTO #tab
select 'TRP997', 1, 'PMP1V-20-XX' UNION ALL
select 'TRP997', 2, 'PMP1V-20-XX' UNION ALL
select 'TRP997', 3, '51154-XX' UNION ALL
select 'TRP997', 4, '51154-XX' UNION ALL
select 'TRB999', 1, '10-61292-X' UNION ALL
select 'TRB999', 2, '10-61292-X' UNION ALL
select 'TRB999', 3, '940732' UNION ALL
select 'TRB999', 4, '961627'
SELECT MB001,
ROW_NUMBER()OVER(PARTITION BY mb001 ORDER BY MB001)MB002,
MB003 FROM (
SELECT ROW_NUMBER()OVER(PARTITION BY mb003 ORDER BY MB001)id,* FROM #tab
) a WHERE id=1
ORDER BY a.MB001 desc
MB001