日期:2014-05-17  浏览次数:20485 次

过滤重复数据
字段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,
       ListClothImageSmall
FROM   (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)b
WHERE  rn = 1

------解决方案--------------------
SQL code
SELECT ListClothID,
       ListClothImageSmall
FROM   (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)b
WHERE  rn = 1