当前位置:网站首页>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 .
边栏推荐
- 《PyTorch深度学习实践》-B站 刘二大人-day7
- 读取图片 进行空间转换 展现不同颜色空间
- Eye tracking in virtual reality
- Pytorch deep learning practice-b station Liu erden-day7
- wireshark抓包:错误分析
- Preorder traversal of binary tree
- Preparation of blast Library of rust language from scratch (1) -- Introduction to the basics of blas
- Experiment class II and object definition initialization
- [force buckle] realize stack with queue
- Arabic numerals to Chinese
猜你喜欢

Set the index library structure, add suggestions that can be automatically completed to users, and turn some fields into collections and put them into suggestions

Experiment class II and object definition initialization

Salgaze: personalized gaze estimation using visual saliency

Read pictures and convert them to show different color spaces

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

Automatic completion & (custom) Pinyin word Separator &

Arabic numerals to Chinese

Restclient query document

wireshark抓包:错误分析

基于运动和视觉突出性的自我视频中的注意预测
随机推荐
Experiment 3 inheritance and derived classes
从零开始的 Rust 语言 blas 库之预备篇(2)—— blas 矩阵格式详解
Some problems encountered in work
手把手搭建家用 NAS 全能服务器(1)| 配置选择及准备
渣渣学习之路(2)纯小白向:Win Server 2003服务器搭建
C language specifies how many days to display from the date
三维凝视估计,没有明确的个人校准2018
吴恩达机器学习第10-11章
Sword finger offer brush questions
网络中的一些基本概念
Restapi implementation of automatic completion & case implementation (search box input for automatic completion)
机器学习篇-逻辑回归的分类预测
[force buckle] bracket matching
颜色直方图 灰度图&彩色图
Seachest utilities tool enables your hard disk to consume less power and live longer
wireshark抓包:错误分析
Open source online markdown editor -- [editor.md]
Restapi implements aggregation (dark horse tutorial)
Busybox specified date modification temporarily does not require clock -w to write to hardware
吴恩达机器学习第3-4章