分组后,取出第一条
程序员文章站
2022-07-13 07:58:52
...
如果groupby之后select之内没有聚合函数操作,则输出每一组的第一条
所以说为了获取每一组的最后一条,只需要用orderby逆序一下就行
SELECT *
FROM (
select p.id as id, p.`column` as `column`, p.`value` as `value`, p.history_begin_time as history_begin_time, p.history_end_time as history_end_time
from cmdbcoresvrdb.p_fixednetworkelement p
WHERE p.id = 0x11E8A2BD695CD4C692DB286ED288C859 and p.history_begin_time < 1564651822799
ORDER BY history_begin_time DESC
) AS part
GROUP BY `column`
————————————————
版权声明:本文为CSDN博主「西工大苗苗」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_36323559/article/details/98616562
所以说为了获取每一组的最后一条,只需要用orderby逆序一下就行
SELECT *
FROM (
select p.id as id, p.`column` as `column`, p.`value` as `value`, p.history_begin_time as history_begin_time, p.history_end_time as history_end_time
from cmdbcoresvrdb.p_fixednetworkelement p
WHERE p.id = 0x11E8A2BD695CD4C692DB286ED288C859 and p.history_begin_time < 1564651822799
ORDER BY history_begin_time DESC
) AS part
GROUP BY `column`
————————————————
版权声明:本文为CSDN博主「西工大苗苗」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_36323559/article/details/98616562
上一篇: mysql8 安装步骤