码迷,mamicode.com
首页 > 数据库 > 详细

sql如何根据时间取出最新的数据记录

时间:2017-07-26 12:39:57      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:date   nbsp   --   and   exists   user   查询   记录   tom   

1-如何根据时间取出最新的数据记录

例子:table1 :
userCode   name            datetime
107        tom            2017/6/21 22:34
107        tom            2017/6/24 10:21
107   tom            2017/12/7 10:45
107   tom            2017/1/15 14:01
107   tom           2017/12/26 14:11
208   jack            2017/6/21 22:36
208   jack          2017/11/15 10:46
208   jack            2017/1/19 9:12
208   jack            2017/1/10 13:57
208   jack           2017/1/22 10:08
309   ben           2017/6/22 12:54
309   ben           2017/3/11 9:16
309   ben           2017/1/10 11:18
309   ben           2017/12/20 15:09

select a.*
from table1 a
where not exists(select 1
from table1 b
where b.name=a.name and b.datetime>a.datetime);


select 1 from table ---查询符合条件的记录的行数

sql如何根据时间取出最新的数据记录

标签:date   nbsp   --   and   exists   user   查询   记录   tom   

原文地址:http://www.cnblogs.com/mjbenkyo/p/7238870.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!