【问题标题】:sql - multiple table select last value namesql - 多表选择最后一个值名称
【发布时间】:2020-03-23 03:01:51
【问题描述】:

我在 mariadb 数据库中有五个表,我想选择每个名称表的最后一个值,

我执行此 sql 命令以获得主机、名称和严重性,

我试过这个 sql 命令:

select host, e.name, e.severity
from hosts
left join items i on (i.hostid = hosts.hostid)
inner join functions f on (f.itemid = i.itemid)
inner join triggers t on (t.triggerid = f.triggerid)
INNER JOIN events e ON (e.objectid = t.triggerid)
group by hosts.hostid;

我想要最后一个主机、名称和严重性, 我想要这个结果在 sql 中:

【问题讨论】:

标签: sql mariadb zabbix groupwise-maximum


【解决方案1】:

我假设 triggerid 在触发器表中是增量的来回答这个问题

select host, e.name, e.severity
from hosts
left join items i on (i.hostid = hosts.hostid)
inner join functions f on (f.itemid = i.itemid)
inner join triggers t on (t.triggerid = f.triggerid)
INNER JOIN events e ON (e.objectid = t.triggerid)
where t.triggerid = (select max(t.triggerid) from triggers)

【讨论】:

  • 你的请求很长,没有结果@zip
  • 我不知道为什么查询很长
猜你喜欢
  • 2017-02-05
  • 1970-01-01
  • 2012-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-21
  • 1970-01-01
  • 2021-08-30
相关资源
最近更新 更多