oracle的union去重吗,数据库UNION DISTINCT去重并且排序

select DISTINCT companyId,

companyCode,

companyName,

-- 相同字段去重,从相同字段取出最小显示一行

businessType ,min(display) display from (

(select

s.company_id companyId,

s.company_code companyCode,

s.company_name companyName,

s.business_type businessType ,

'1' display  --用自定义字段区分显示顺序

from nclm_servicer_info s

-- 省 市 类别相同优先排列

join NCLM_SERVICER_RELATION nsrp on nsrp.COMPANY_ID=S.company_id AND nsrp.RELATION_TYPE='2' and nsrp.VALID_IND='1' AND nsrp.RELATION_TYPE_ID=#{servicerInfoQueryVo.businessAreaProvince}

join NCLM_SERVICER_RELATION nsrc on nsrc.COMPANY_ID=S.company_id AND nsrc.RELATION_TYPE='3' and nsrc.VALID_IND='1' AND nsrc.RELATION_TYPE_ID=#{servicerInfoQueryVo.businessAreaCity}

join NCLM_SERVICER_RELATION nsrr on nsrr.COMPANY_ID=S.company_id AND nsrr.RELATION_TYPE='4' and nsrr.VALID_IND='1' AND nsrr.RELATION_TYPE_ID=#{servicerInfoQueryVo.riskClass}

where s.company_type = '2' and s.valid_ind= '1')

union

(select

s.company_id companyId,

s.company_code companyCode,

s.company_name companyName,

s.business_type businessType ,

'2' display

from nclm_servicer_info s

-- 省 市 相同优先排第二

join NCLM_SERVICER_RELATION nsrp on nsrp.COMPANY_ID=S.company_id AND nsrp.RELATION_TYPE='2' and nsrp.VALID_IND='1' AND nsrp.RELATION_TYPE_ID=#{servicerInfoQueryVo.businessAreaProvince}

join NCLM_SERVICER_RELATION nsrc on nsrc.COMPANY_ID=S.company_id AND nsrc.RELATION_TYPE='3' and nsrc.VALID_IND='1' AND nsrc.RELATION_TYPE_ID=#{servicerInfoQueryVo.businessAreaCity}

where s.company_type = '2' and s.valid_ind= '1')

union

(select

s.company_id companyId,

s.company_code companyCode,

s.company_name companyName,

s.business_type businessType ,

'3' display

from nclm_servicer_info s

-- 类别相同排第三

join NCLM_SERVICER_RELATION nsrr on nsrr.COMPANY_ID=S.company_id AND nsrr.RELATION_TYPE='4' and nsrr.VALID_IND='1' AND nsrr.RELATION_TYPE_ID=#{servicerInfoQueryVo.riskClass}

where s.company_type = '2' and s.valid_ind= '1')

union

(select

s.company_id companyId,

s.company_code companyCode,

s.company_name companyName,

s.business_type businessType ,

'4' display

-- 其他排列在最后

from nclm_servicer_info s

where s.company_type = '2' and s.valid_ind= '1')

) tw

where 1=1

-- 加入筛选条件

group by companyId,

companyCode,

companyName,

businessType order by display --根据相同字段分组 ,显示顺序字段排序

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值