首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

过滤反复数据

2012-11-13 
过滤重复数据字段1ListClothID字段2ListClothImageSmall12221333144425552ddd3f3v想得到122225553fselect

过滤重复数据
字段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 

热点排行