当前位置:网站首页>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
边栏推荐
- Remote code execution in Win 11 using wpad / PAC and JScript 1
- Tensorflow 2 basic operation dictionary
- PCA based geometric feature calculation of PCL point cloud processing (52)
- What is the difference between a host and a server?
- Development of Matlab GUI bridge auxiliary Designer (functional introduction)
- R language survival package coxph function to build Cox regression model, ggrisk package ggrisk function and two_ Scatter function visualizes the risk score map of Cox regression, interprets the risk
- Change the material of unity model as a whole
- Remote code execution in Win 11 using wpad / PAC and JScript
- JDBC tool class jdbcfiledateutil uploads files and date format conversion, including the latest, simplest and easiest way to upload single files and multiple files
- 论文写作 19: 会议论文与期刊论文的区别
猜你喜欢
2022DASCTF Apr X FATE 防疫挑战赛 CRYPTO easy_real
Recommend an open source free drawing software draw IO exportable vector graph
Zdns was invited to attend the annual conference of Tencent cloud basic resources and share the 2020 domain name industry development report
Operation of numpy array
. Ren -- the intimate artifact in the field of vertical Recruitment!
Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model
Installation and use of NVM
Handwritten Google's first generation distributed computing framework MapReduce
selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
SIGIR'22「微软」CTR估计:利用上下文信息促进特征表征学习
随机推荐
Commit and rollback in DCL of 16 MySQL
如何做产品创新?——产品创新方法论探索一
nc基础用法3
Modeling based on catiav6
堡垒机、跳板机JumpServer的搭建,以及使用,图文详细
Es error: request contains unrecognized parameter [ignore_throttled]
R language survival package coxph function to build Cox regression model, ggrisk package ggrisk function and two_ Scatter function visualizes the risk score map of Cox regression, interprets the risk
Investigate why close is required after sqlsession is used in mybatties
Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model
波场DAO新物种下场,USDD如何破局稳定币市场?
Wave field Dao new species end up, how does usdd break the situation and stabilize the currency market?
Why does ES6 need to introduce map when JS already has object type
ABAQUS script email auto notification
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
Click an EL checkbox to select all questions
nc基础用法4
SIGIR'22 "Microsoft" CTR estimation: using context information to promote feature representation learning
Leetcode dynamic planning training camp (1-5 days)
After route link navigation, the sub page does not display the navigation style problem
Cadence OrCAD capture batch change component packaging function introduction graphic tutorial and video demonstration