SQL 按 Unix 时间戳中最旧的顺序排序

发布于 2024-08-28 14:02:05 字数 57 浏览 3 评论 0原文

如何使用 SQL 按最旧的顺序对结果进行排序?我正在使用 unix 时间戳。

谢谢。

How do I use SQL to order results by oldest first? I am using unix timestamps.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

赠意 2024-09-04 14:02:05

最旧的 UNIX 时间戳是最小的,因此您需要ORDER BY my_timestamp_column ASC

我不知道为什么到目前为止两个答案都说要按 DESC 列排序。

The oldest UNIX timestamp is the one that's smallest, so you want to ORDER BY my_timestamp_column ASC.

I have no idea why both the answers so far have said to order by the column DESC.

情绪操控生活 2024-09-04 14:02:05

Unix 时间或 POSIX 时间是一种描述时间点的系统,定义为自 1970 年 1 月 1 日午夜预产协调世界时 (UTC) 以来经过的秒数,不包括闰秒

ORDER BY 子句可以使用 ASC 或DESC,如果您不指定,它将默认使用 ASC:

首先是最近的时间戳:

SELECT * FROM tableName ORDER BY columnName DESC

首先是最近的时间戳:

SELECT * FROM tableName ORDER BY columnName ASC

Unix time, or POSIX time, is a system for describing points in time, defined as the number of seconds elapsed since midnight proleptic Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds

The ORDER BY clause can use ASC or DESC, if you sepcify none it will default to use ASC:

Most recent time stamps first:

SELECT * FROM tableName ORDER BY columnName DESC

Less recent time stamps first:

SELECT * FROM tableName ORDER BY columnName ASC
别忘他 2024-09-04 14:02:05

您在使用 ORDER BY 'unix-time-stamp-field' ASC; 时遇到什么问题?

编辑:jemfinch是正确的,它是ASC

What's the problem you're having using ORDER BY 'unix-time-stamp-field' ASC;?

EDIT: jemfinch is right, it is ASC.

眼角的笑意。 2024-09-04 14:02:05

为了在使用 unix_timetamp 时获取最早的第一个数据,请运行以下查询:

Select * FROM tablename order by FROM_UNIXTIME(ts) ASC

此处:
ts 响应表中包含 unix_timestamp 的列。

In order to get oldest first data when using unix_timetamp, run this query:

Select * FROM tablename order by FROM_UNIXTIME(ts) ASC

here:
ts respond to column of the table which has unix_timestamp.

嗫嚅 2024-09-04 14:02:05

使用 ORDER BY带有 DESC 修饰符的子句可反转结果:

SELECT ... FROM ... ORDER BY timestampCol DESC;

编辑

当然您应该使用 ASC (或不使用,因为 ASC 是默认值)...; )

Use ORDER BY clause with DESC modifier that reverses the results:

SELECT ... FROM ... ORDER BY timestampCol DESC;

Edit

Of course you should use ASC (or none, cause ASC is default)... ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文