0

Подскажите, пожалуйста, можно ли получить сумму SUM(t.value) по этим данным из базы заббикса? Это айтемы с разных устройств, которые я опрашиваю с одинаковым промежутком, в графане пытаюсь построить суммированный график, один, вместо двух. Данные t.value - просто целые значения. Можно ли сделать из двух запросов один?

select t.value as Данные1, t.clock as time 
from hosts h, items i,history_uint t
where i.hostid=h.hostid and t.itemid=i.itemid and i.hostid='112233' and t.itemid = '0112233'
select t.value as Данные2, t.clock as time
from hosts h, items i, history_uint t 
where i.hostid=h.hostid and t.itemid=i.itemid and i.hostid='223344'   and t.itemid = '0223344'

1 ответ 1

0

Если просто объединить, то

select t.value as Данные, t.clock as time 
from hosts h, items i,history_uint t
where i.hostid=h.hostid and t.itemid=i.itemid and i.hostid='112233' and t.itemid = '0112233'
  union all
select t.value as Данные, t.clock as time
from hosts h, items i, history_uint t 
where i.hostid=h.hostid and t.itemid=i.itemid and i.hostid='223344'   and t.itemid = '0223344'

Если все таки требуется сумма, например Данные2 это количество, которое можно сложить, то

select
  sum(g.data) as Данные, g.time
from (
select t.value as data, t.clock as time 
from hosts h, items i,history_uint t
where i.hostid=h.hostid and t.itemid=i.itemid and i.hostid='112233' and t.itemid = '0112233'
  union all
elect t.value as data, t.clock as time
from hosts h, items i, history_uint t 
where i.hostid=h.hostid and t.itemid=i.itemid and i.hostid='223344'   and t.itemid = '0223344') g
group by g.time

В этом случае в обоих запросах должны встерчаться строки с одинковым временем, иначе результат будет как в первом варианте.

Для справки: в инструкции UNION ALL имена полей называются по первому запросу.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.