过滤掉数据中的重复数据,并且只保留一条
各位,我遇到了一个对我而言很大的麻烦,对于一个sql的语句如何去过滤掉数据中的重复数据,并且只保留一条数据供使用,但是我这里的过滤是不能对其进行删除,只是单纯的过滤掉它。
select GID = ROW_NUMBER() over (order by convert(int ,XL.DJL) desc),XL.* from (select XL.XLMC,XL.XLTS,XL.F_219930215757439 XLID,XL.TP,XL.DJL,XL.FBSJ,XL.ZXL,'gny/ztslb' LINK from DEFINE_CXSYXLTJLB TJ inner join DEFINE_XL_GN XL on (TJ.XLID=XL.F_219930215757439) UNION ALL select XL.XLMC,XL.XLTS,XL.F_219930215757439 XLID,XL.TP,XL.DJL,XL.FBSJ,XL.ZXL,'cjy/ztslb' LINK from DEFINE_CXSYXLTJLB TJ inner join DEFINE_XL_CJ XL on (TJ.XLID=XL.F_219930215757439) UNION ALL select XL.XLMC,XL.XLTS,XL.F_219930215757439 XLID,XL.TP,XL.DJL,XL.FBSJ,XL.ZXL,'zby/ztslb' LINK from DEFINE_CXSYXLTJLB TJ inner join DEFINE_XL_ZTC XL on (TJ.XLID=XL.F_219930215757439) UNION ALL select XL.XLMC,XL.XLTS,XL.F_219930215757439 XLID,XL.TP,XL.DJL,XL.FBSJ,XL.ZXL,'zyx/ztslb' LINK from DEFINE_CXSYXLTJLB TJ inner join DEFINE_ZYX XL on (TJ.XLID=XL.F_219930215757439)) XL order by convert(int ,XL.DJL) desc ;
为了让各位帮助我的大神看清楚我再把上面的代码复制一下:
select GID = ROW_NUMBER() over (order by convert(int ,XL.DJL) desc),XL.* from (select XL.XLMC,XL.XLTS,XL.F_219930215757439 XLID,XL.TP,XL.DJL,XL.FBSJ,XL.ZXL,'gny/ztslb' LINK from DEFINE_CXSYXLTJLB TJ inner join DEFINE_XL_GN XL on (TJ.XLID=XL.F_219930215757439) UNION ALL select XL.XLMC,XL.XLTS,XL.F_219930215757439 XLID,XL.TP,XL.DJL,XL.FBSJ,XL.ZXL,'cjy/ztslb' LINK from DEFINE_CXSYXLTJLB TJ inner join DEFINE_XL_CJ XL on (TJ.XLID=XL.F_219930215757439) UNION ALL select XL.XLMC,XL.XLTS,XL.F_219930215757439 XLID,XL.TP,XL.DJL,XL.FBSJ,XL.ZXL,'zby/ztslb' LINK from DEFINE_CXSYXLTJLB TJ inner join DEFINE_XL_ZTC XL on (TJ.XLID=XL.F_219930215757439) UNION ALL select XL.XLMC,XL.XLTS,XL.F_219930215757439 XLID,XL.TP,XL.DJL,XL.FBSJ,XL.ZXL,'zyx/ztslb' LINK from DEFINE_CXSYXLTJLB TJ inner join DEFINE_ZYX XL on (TJ.XLID=XL.F_219930215757439)) XL order by convert(int ,XL.DJL) desc ;
由于小弟我经常在问问题所以分数已经不多了,不过还是恳求大神的帮助啊!