oracle 多字段查询数据排重,除了row_number()over(partition by )还能怎么实现

[复制链接]
查看11 | 回复3 | 2010-7-21 13:58:40 | 显示全部楼层 |阅读模式
如题,distinct和group by不适用,只对表中某一字段排重但是查询结果中要包含所有的字段信息。
select * from (select id,userid,gjzy,xhsj,lrsj,wlbm,wlmc,wldw,wldj,wlnum,xhyy,jhdep,jx,qk ,
row_number()over(partition by gjzy order by userid desc,lrsj desc) rm from cb_rqrj_djclhs
where 1=1and jhdep = '100110011013' )a where a.rm=1
and userid = '1kwxdlxq' and substr(lrsj,1,4) between '2010' and '2010'
除了上面的实现方法还有什么方法能实现,通过子查询或内查询能实现么?!

回复

使用道具 举报

千问 | 2010-7-21 13:58:40 | 显示全部楼层
对重复字段只取包括其中一个的记录的方法就这样,还可以通过唯一id(如果存在的话,没有的话,用row_number)比较如select * from cb_rqrj_djclhs awhere ID in (select min(id) from cb_rqrj_djclhs where gjzy=a.gjzy)
回复

使用道具 举报

千问 | 2010-7-21 13:58:40 | 显示全部楼层
select字段1,字段2fromtable_namwhereXlike'%X%'orXlike'%Y%'orXlike'%Z%'--这个是把只要包含X或Y或Z的数据都查出来select字段1,字段2fromtable_namwhereXlike'%X%'and
回复

使用道具 举报

千问 | 2010-7-21 13:58:40 | 显示全部楼层
select字段1,字段2fromtable_namwhere Xlike'%X%'orXlike'%Y%'orXlike'%Z%'--这个是把只要包含X或Y或Z的数据都查出来select字段1,字段2fromtable_namwhere Xlike'%X%'an
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行