sql根据某一个字段重复只取第一条数据
2018-08-18 14:20 更新
SELECT * FROM(
SELECT V.VENDOR_CODE,
V.VENDOR_NAME,
V.VENDOR_TYPE,
V.SMTP_ADDR,
V.MOB_NUMBER,
U.USER_NAME,
ROW_NUMBER() OVER(ORDER BY V.VENDOR_CODE) AS RN
FROM T_BD_VENDOR V,
T_BASE_USER U,
'(SELECT S.*
FROM (
SELECT T.*, ROW_NUMBER() OVER (PARTITION BY T.VENDOR_CODE ORDER BY T.USER_CODE) AS GROUP_IDX
FROM T_BD_USER_VENDOR_REL T
)S
WHERE S.GROUP_IDX = 1
)R'
WHERE 1=1
AND V.VENDOR_CODE = R.VENDOR_CODE(+)
AND R.USER_CODE = U.USER_CODE(+)
)
WHERE RN BETWEEN 1 AND 20
其中绿色部分表示从中间关联表中根据VENDOR_CODE字段重复的只取出一条。 如上图只取出根据VENDOR_CODE分组,根据USER_CODE排序的第一条数据。
以上内容是否对您有帮助:
更多建议: