读书人

过滤反复数据

发布时间: 2012-11-13 10:00:50 作者: rapoo

过滤重复数据
字段1 ListClothID 字段2 ListClothImageSmall
1 222
1 333
1 444
2 555
2 ddd
3 f
3 v

想得到 1 222
2 555
3 f

select a.ListClothID , b.ListClothImageSmall
from (select distinct ListClothID from ListClothImage) as a left join ListClothImage b on a.ListClothID = b.ListClothID


[解决办法]

SQL code
SELECT ListClothID,       ListClothImageSmallFROM   (SELECT Row_number()                 OVER(                   ORDER BY a.ListClothID )rn,               a.ListClothID,               b.ListClothImageSmall        FROM   (SELECT DISTINCT ListClothID                FROM   ListClothImage) AS a               LEFT JOIN ListClothImage b                      ON a.ListClothID = b.ListClothID)bWHERE  rn = 1
[解决办法]
SQL code
SELECT ListClothID,       ListClothImageSmallFROM   (SELECT Row_number()                 OVER(                   ORDER BY a.ListClothID )rn,               a.ListClothID,               b.ListClothImageSmall        FROM   (SELECT DISTINCT ListClothID                FROM   ListClothImage) AS a               LEFT JOIN ListClothImage b                      ON a.ListClothID = b.ListClothID)bWHERE  rn = 1 

读书人网 >SQL Server

热点推荐