大于 一个数 oracle 标记,一道SQL面试题:oracle, 分类汇总, 标记相同id第一条有效...

试题

表数据:table1:

id     name    name_wt cert   cert_wt

--------------------------------------------

A12510

A2477

Ba3Ha11

Bb999C10

查询结果:table2

id     name    name_wt cert   cert_wt

--------------------------------------------

A1277

Ba3C10

请根据table2的要求,通过编写SQL语句实现:根据ID分组,每个字段值对应的WT最小。

答案:

select A.id, A.name, A.name_wt, B.cert, B.cert_wt

from (select *

from (select t1.id,

t1.name,

t1.name_wt,

row_number() over(partition by id order by to_number(t1.name_wt) asc) unit_id

from table1t1)

where unit_id = 1) A

left join (select *

from (select t1.id,

t1.cert,

t1.cert_wt,

row_number() over(partition by id order by to_number(t1.cert_wt) asc) unit_id

from table1t1)

where unit_id = 1) B

on a.id = b.id

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值