Oracle查询和聚合功能 [英] Oracle query and aggregate function

查看:97
本文介绍了Oracle查询和聚合功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在oracle中有表名employee_1.如果mobile_no和sim_no是相同的,我要选择最大开始日期.我已经尝试过,但是没有成功.请帮忙 员工_1表位于

I have table name employee_1 suppose in oracle. If the mobile_no and sim_no is same i want select maximum start_date. I have tried , but no success. Please help The employee_1 table is below

Mobile_No   Sim_NO      Start_Date         End_Date 
1111111111  1111111111  3/10/2017 21:02:44  10/10/2017 21:02:44
1111111111  1111111111  11/10/2017 21:02:44 13/10/2017 21:02:44
1111111111  1111111112  11/10/2017 21:02:44 13/10/2017 21:02:44
1111111111  1111111111  12/10/2017 21:02:44 

我要显示2行

1111111111  1111111111  12/10/2017 21:02:44
1111111111  1111111112  11/10/2017 21:02:44 13/10/2017 21:02:44

推荐答案

尝试一下,希望它可以满足您的要求.

Try this, hopefully, it fulfills your requirement.

select mobile_no,sim_no,start_date,end_date from(
select mobile_no,sim_no,start_date,end_date,rank() over(partition by mobile_no,sim_no order by start_date desc) rn from employee_1)s
where rn=1

这篇关于Oracle查询和聚合功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆