如何获取上次将不同行插入数据库的顺序? [英] How to get the order distinct rows were last inserted into a database?

查看:26
本文介绍了如何获取上次将不同行插入数据库的顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对我的另一个问题的更直接的跟进:

This is a more to the point follow-up of my other question:

给定一张桌子:

CREATE TABLE events (
    order TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    value INT NOT NULL
);

每次插入时,value 将从有限集合中取出.

At every insertion, value will be taken from a finite set.

如何获得我集合中所有元素最后插入数据库的顺序?我想过 SELECT DISTINCT value FROM event ORDER BY "order" DESC;,但根据我另一个问题中的回答,这行不通.

How do I get the order all the elements of my set were last inserted into the database? I thought of doing SELECT DISTINCT value FROM event ORDER BY "order" DESC;, but according to answer in my other question, this won't work.

推荐答案

来自您其他帖子的回答.

Answer from your other post.

对用户使用 max 和分组,您可以获得用户的最新时间戳.

Using max and grouping on the user you get the most recent timestamp by user.

SELECT 
    MAX([order]) AS MaxOrd
  , value
FROM Event
GROUP BY value
ORDER BY MaxOrd DESC

这篇关于如何获取上次将不同行插入数据库的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆