Home > Database > Mysql Tutorial > Sqlserver 如何获取每组中的第一条记录_MySQL

Sqlserver 如何获取每组中的第一条记录_MySQL

PHP中文网
Release: 2016-05-27 13:46:48
Original
1258 people have browsed it

在日常生活方面,我们经常需要记录一些操作,类似于日志的操作,最后的记录才是有效数据,而且可能它们属于不同的方面、功能下面,从数据库的术语来说,就是查找出每组中的一条数据。

 

例子

Sqlserver 如何获取每组中的第一条记录_MySQL

我们要从上面获得的有效数据为:

Sqlserver 如何获取每组中的第一条记录_MySQL

对应的sql:

select * from t1 t where id = (select top 1 id from t1 where grp = t.grp order by createtime desc )
Copy after login

以上就是Sqlserver 如何获取每组中的第一条记录_MySQL的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Problem with tp6 connecting to sqlserver database
From 1970-01-01 08:00:00
0
0
0
Unable to connect to SQL Server in Laravel
From 1970-01-01 08:00:00
0
0
0
Methods of parsing MYD, MYI, and FRM files
From 1970-01-01 08:00:00
0
0
0
SQLSTATE: User login failed
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template