删除记录
我有一个表 [user_logs] ,其中包含以下字段 [username]、[datetimelog]
示例数据
==============
user1 2011-06-28 08:49:01
user2 2011-06-28 08:59:38
user3 2011-06-28 09:04:31
user4 2011-06-28 10:00:15
user2 2011-06-28 10:28:54
user1 2011-06-29 08:31:22
user9 2011-06-29 08:32:32
user2 2011-06-29 10:13:53
user1 2011-06-29 13:11:15
我想知道如何创建 SQL 删除查询来删除除最后一个日志之外的所有用户日志,以便上面的示例将在之后生成以下内容删除查询
user1 2011-06-29 13:11:15
user2 2011-06-29 10:13:53
user3 2011-06-28 09:04:31
user4 2011-06-28 10:00:15
user9 2011-06-29 08:32:32
I have a table [user_logs] with the following fields [username], [datetimelog]
Sample Data
==============
user1 2011-06-28 08:49:01
user2 2011-06-28 08:59:38
user3 2011-06-28 09:04:31
user4 2011-06-28 10:00:15
user2 2011-06-28 10:28:54
user1 2011-06-29 08:31:22
user9 2011-06-29 08:32:32
user2 2011-06-29 10:13:53
user1 2011-06-29 13:11:15
I want to know how to create an SQL Delete query to delete all user logs EXCEPT their last log so that the above example will produce the following after a DELETE query
user1 2011-06-29 13:11:15
user2 2011-06-29 10:13:53
user3 2011-06-28 09:04:31
user4 2011-06-28 10:00:15
user9 2011-06-29 08:32:32
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
怎么样:
这可行吗?
What about:
Could that work?
这里删除一行,如果不是同一user_id组内的最长时间
Here delete a row, if its not the maximum time in group with the same user_id
尝试一下
Try that