查找给定表中的第一个和最后一个记录

编程入门 行业动态 更新时间:2024-10-28 06:23:24
本文介绍了查找给定表中的第一个和最后一个记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

heyy ...... 我想查询,查找给定表格中的第一个和最后一个记录但我想要某些条件的结果.. 这里是我的表数据:

heyy... I want a query, to find the first and last records in a given table but I want the result by some condition.. here is my table data :

No. starttime Endtime ------- --------- -------- 0500000001 06:52 06:59 0500000001 07:00 07:27 0500000001 07:28 08:09 0500000001 08:14 08:40 0500000001 08:42 10:00 0500000001 10:01 11:29 0500000001 11:31 12:41 0500000001 12:43 13:28 0500000144 10:59 11:03 0500000144 11:03 11:04 0500000144 11:05 11:07 0500000144 11:08 11:37 0500000144 11:37 09:47 0500000144 09:47 09:51 0500000144 09:52 09:53 0500000144 09:54 10:46 0500000144 10:47 11:12 0500000144 11:13 11:16 0500000144 11:17 13:02 0500000144 13:02 09:29 0500000144 13:29 09:29

这里我希望我的结果像这样

here I want My result as like this

No. starttime Endtime ------ ---------- -------- 0500000001 06:52 13:28 0500000144 10:59 09:29

ie。第一条记录和最后一条记录号 任何想法如何在mysql中编写查询...?

ie. first record and last record of No. Any idea how to write query in mysql...?

推荐答案

Google [ ^ ]它? 尝试这种格式.. 获得第一条记录: Do you Google[^] it? Try in this format.. To get the first record: select col1,col2,col3 from tab1 order by col1 asc limit 1;

获取最后一条记录:

To get the last record:

select col1,col2,col3 from tab1 order by col1 desc limit 1;

试试这样 Try like this DECLARE @Vehicle TABLE ( VehicleNo NVARCHAR(50),Datetime1 Datetime,Datetime2 Datetime); INSERT INTO @Vehicle (VehicleNo,Datetime1,Datetime2) VALUES('0500000001','06:52','06:59') INSERT INTO @Vehicle (VehicleNo,Datetime1,Datetime2) VALUES('0500000001','07:00','07:27') INSERT INTO @Vehicle (VehicleNo,Datetime1,Datetime2) VALUES('0500000144','10:59','11:03') SELECT top 1 * FROM @Vehicle WHERE VehicleNo=(SELECT MIN(VehicleNo) FROM @Vehicle) UNION SELECT top 1 * FROM @Vehicle WHERE VehicleNo=(SELECT MAX(VehicleNo) FROM @Vehicle)

stackoverflow/questions/2735395/how-to-find-first -and-last-record-from-mysql-table get-the-last-last-last-record-of-db [ ^ ] 检查链接..希望它有帮助.. stackoverflow/questions/2735395/how-to-find-first-and-last-record-from-mysql-table get-the-first-and-last-record-of-db[^] Check the link..hope it will help..

更多推荐

查找给定表中的第一个和最后一个记录

本文发布于:2023-10-18 06:10:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1503355.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第一个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!