当前位置:网站首页>SQL gets the latest record of the data table
SQL gets the latest record of the data table
2022-04-23 20:21:00 【First code】
In the flow record table , A user usually generates many records if only the latest one , Can use max To get .
As shown in the file upload record table , Get the file upload record table , The latest record generated by each user :
select * from file_record as a inner join (
select file_author,max(file_ctime) as file_ctime from file_record group by file_author) as b
on a.file_author=b.file_author
and a.file_ctime=b.file_ctime
By using max、group by、inner join You can get the latest data record of each user ;
If you just need everyone's latest operation time , Just use b The content of :
select file_author,max(file_ctime) as file_ctime from file_record group by file_author
Project instance :
select TableKey, full name , Department name , contact number , ID number
from essential information _ Summary where Effective or not =1 and ( Where like @county+'%')) as a
inner join (
select ID number ,max( Meal time ) as Meal time
from [ Meal details summary ] where Where like @county+'%' and datediff(day, Meal time ,getdate())>=3 group by ID number ) as b
on a. ID number =b. ID number
If you want to say select Get the result set and insert it into other tables , It can be used :insert into #temp, Such as
insert into #tempOldman select TableKey, full name , Department name , contact number , Meal time from (
select TableKey, full name , Department name , contact number , ID number from essential information _ Summary
where Effective or not =1 and ( Where like @county+'%')) as a
inner join (
select ID number ,max( Meal time ) as Meal time from [ Meal details summary ]
where Where like @county+'%' and datediff(day, Meal time ,getdate())>=3 group by ID number ) as b
on a. ID number =b. ID number
版权声明
本文为[First code]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210551268217.html
边栏推荐
- Es index (document name) fuzzy query method (database name fuzzy query method)
- The flinkcdc reports an error: but this is no longer available on the server
- Common form verification
- Remote code execution in Win 11 using wpad / PAC and JScript
- Intersection calculation of straight line and plane in PCL point cloud processing (53)
- Numpy sort search count set
- LeetCode动态规划训练营(1~5天)
- Numpy mathematical function & logical function
- Remote code execution in Win 11 using wpad / PAC and JScript 1
- ArcGIS js api 4. X submergence analysis and water submergence analysis
猜你喜欢
【PTA】整除光棍
Livego + ffmpeg + RTMP + flvjs to realize live video
CVPR 2022 | QueryDet:使用级联稀疏query加速高分辨率下的小目标检测
Azkaban recompile, solve: could not connect to SMTP host: SMTP 163.com, port: 465 [January 10, 2022]
Operation of numpy array
Automatically fill in body temperature and win10 task plan
Commit and ROLLBACK in DCL of 16mysql
SQL Server Connectors By Thread Pool | DTSQLServerTP 插件使用说明
Mysql database backup scheme
Don't bother tensorflow learning notes (10-12) -- Constructing a simple neural network and its visualization
随机推荐
NC basic usage 4
Azkaban recompile, solve: could not connect to SMTP host: SMTP 163.com, port: 465 [January 10, 2022]
Redis installation (centos7 command line installation)
Confusion about thread blocking after calling the read () method of wrapper flow
Rédaction de thèses 19: différences entre les thèses de conférence et les thèses périodiques
R语言使用econocharts包创建微观经济或宏观经济图、indifference函数可视化无差异曲线、自定义计算交叉点、自定义配置indifference函数的参数丰富可视化效果
Computing the intersection of two planes in PCL point cloud processing (51)
Is the wechat CICC wealth high-end zone safe? How to open an account for securities
PCL点云处理之基于PCA的几何形状特征计算(五十二)
论文写作 19: 会议论文与期刊论文的区别
【PTA】L1-006 连续因子
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
R语言使用caret包的preProcess函数进行数据预处理:对所有的数据列进行BoxCox变换处理(将非正态分布数据列转换为正态分布数据、不可以处理负数)、设置method参数为BoxCox
Five minutes to show you what JWT is
PCA based geometric feature calculation of PCL point cloud processing (52)
aqs的学习
DNS cloud school rising posture! Three advanced uses of authoritative DNS
Error reported by Azkaban: Azkaban jobExecutor. utils. process. ProcessFailureException: Process exited with code 127
Livego + ffmpeg + RTMP + flvjs to realize live video
Some basic configurations in interlij idea