当前位置:网站首页>Get the first and last values after Oracle grouping and sorting
Get the first and last values after Oracle grouping and sorting
2022-07-19 06:41:00 【hello,world_ yzs】
ORACLE Get the first and last values after grouping and sorting
Reference link
ORACLE Get the first and last values after grouping and sorting
practice
I met you recently sql The problem of .
wx_user There are some problems with your mobile phone number , A string login occurred . Originally, a user has a mobile number , Now it has become multiple .
The user's initial mobile number is in the login resume WX_USER_LOGIN The first item in the search according to its ID number ( Time ).
Based on the above analysis ,sql as follows :
select u.id id,u.id_no idno,u.mobile wrongmobile,t.id_no tin, t.mobile truemobile from wx_user u,
( select id_no,mobile from (
select
t1.id_no,
t1.mobile,
row_number() over(PARTITION BY t1.id_no order by t1.create_time) rowss1
from (select * from WX_USER_LOGIN t where id_no in
(select id_no from wx_user where mobile in (
select mobile from wx_user group by mobile having count (*)>1))
) t1
)
where rowss1 = '1') t
where u.id_no in(t.id_no)
First , Find out the wrong mobile phone number and the corresponding ID card :
select id_no from wx_user where mobile in (
select mobile from wx_user group by mobile having count (*)>1)
Find out the login resume according to the ID number :
select * from WX_USER_LOGIN t where id_no in
(select id_no from wx_user where mobile in (
select mobile from wx_user group by mobile having count (*)>1))
The above record is table t1
Group sort :
select
t1.id_no,
t1.mobile,
row_number() over(PARTITION BY t1.id_no order by t1.create_time) rowss1
from t1
Take the first item after grouping and sorting
select id_no,mobile from (
select
t1.id_no,
t1.mobile,
row_number() over(PARTITION BY t1.id_no order by t1.create_time) rowss1
from (select * from WX_USER_LOGIN t where id_no in
(select id_no from wx_user where mobile in (
select mobile from wx_user group by mobile having count (*)>1))
) t1
)
where rowss1 = '1'
The first item after grouping and sorting is used as a table t, Combine the original table and table t, Get all the required fields :
select u.id id,u.id_no idno,u.mobile wrongmobile,t.id_no tin, t.mobile truemobile from wx_user u,t where u.id_no in(t.id_no)
select * from a,b where a.id = b.id The meaning changed , This is equivalent to : select * from a inner join b on a.id = b.id. That is, inner connection .
Postscript
Used in grouping PARTITION, It also means partition table . Next, learn the partition table .
边栏推荐
- Convert PNG with transparency to C array
- wireshark抓包:错误分析
- Quelques concepts de base dans le réseau
- 感知智能手机上用户的关注状态
- Application of views and index files
- ORACLE分组排序后获取第一条和最后一条值
- ANAME
- Design and implementation of a gesture control system for tablet computer based on gaze
- CUDA与大数组的双调排序
- Visual saliency based visual gaze estimation
猜你喜欢

mass data

lock

2022/07/12 learning notes (day05) cycle

使用候选选择从人类注视中学习视频显著性
![Open source online markdown editor -- [editor.md]](/img/f3/b37acf934aa2526d99c8f585b6f229.png)
Open source online markdown editor -- [editor.md]

翻转链表

Handle Chinese word segmentation IK word segmenter and expand and stop dictionary

Pytorch deep learning practice-b station Liu erden-day7

《PyTorch深度学习实践》-B站 刘二大人-day7

感知智能手機上用戶的關注狀態
随机推荐
[force buckle] bracket matching
Part of the second Shanxi Network Security Skills Competition (Enterprise Group) WP (II)
[force buckle] flip binary tree
wireshark抓包:错误分析
山西省第二届网络安全技能大赛(企业组)部分赛题WP(四)
手把手搭建家用 NAS 全能服务器(1)| 配置选择及准备
Visual saliency based visual gaze estimation
吴恩达机器学习第12-13章
斑点检测 记录
吴恩达机器学习第1-2章
Creation and implementation of WebService interface
海量数据
F5LTM(一)逻辑关系图
Handle Chinese word segmentation IK word segmenter and expand and stop dictionary
[force buckle] the same tree
Automatic completion & (custom) Pinyin word Separator &
No application for domain name SSL certificate under ports 80 and 443 (applicable to acme.sh and certbot)
一种基于凝视的平板电脑手势控制系统的设计与实现
实验一 简单程序设计
吴恩达机器学习第6-7章