SQL查询 - UNIX时间戳 - 第二个最新日期
我是SQL的新手,只需要创建一个查询即可能够在我的博客上发挥功能,并且我正在对代码进行小步骤,但是我坚持回收第二个最新的Unixtime日期。
SELECT FROM_UNIXTIME(MAX(datum),'%d/%m-%Y') AS newest_postdate_ever,
(SELECT FROM_UNIXTIME(MAX(datum),'%d/%m-%Y') WHERE datum < (SELECT MAX(datum) FROM table-content)) AS second_newest_postdate_ever
[newest_postdate_ever] => 16/04-2022
[second_newest_postdate_ever] =>
但它应该说[second_newest_postdate_ever] =&gt; 15/04-2022
I'm completely new to SQL and just need to create one query to be able to make a function on my blog and I'm taking small steps in the code, but I'm stuck on reciving the second newest unixtime date.
SELECT FROM_UNIXTIME(MAX(datum),'%d/%m-%Y') AS newest_postdate_ever,
(SELECT FROM_UNIXTIME(MAX(datum),'%d/%m-%Y') WHERE datum < (SELECT MAX(datum) FROM table-content)) AS second_newest_postdate_ever
[newest_postdate_ever] => 16/04-2022
[second_newest_postdate_ever] =>
But it supposed to say [second_newest_postdate_ever] => 15/04-2022
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是MySQL版本8,我们可以使用Row_number。如果是较早的版本,我们可以使用变量来执行相同的操作。我给你两个查询。
一旦我们分配了row_number desc,最近的日期就会具有
rn = 1
,并在使用之前获取一个日期,
其中mysql 8
的rn = 2 对于任何
版本结果。 RN = 2是我们想要的。
这给出了您想要的格式。
db&lt;&gt;&gt;
If you are using MySQL version 8 we can use ROW_NUMBER. If it is an earlier version we can do the same thing using a variable. I give you both queries.
Once we have assigned ROW_NUMBER DESC the most recent date has
rn=1
and to get the one before we useWHERE rn = 2
For mySQL 8
For any version of mySQL
The same results. rn = 2 is the one we want.
This gives the format you want.
db<>fiddle here