更新时间:2022-12-09 11:50:12
SELECT
ReqColumns, hostid, name, (TotalUsed/TotalMemory)* 100 AS Value
FROM
(
SELECT
sc.ReqColumns, i.hostid, i.name,
/*TRUNCATE((tu.value_min) / (1024 * 1024 * 1024), 2) AS value_min,
TRUNCATE((tu.value_avg) / (1024 * 1024 * 1024), 2) AS value_avg,
TRUNCATE((tu.value_max) / (1024 * 1024 * 1024), 2) AS value_max,*/
SUM(IF(i.name='Total Memory [used]',TRUNCATE((tu.value_max) / (1024 * 1024 * 1024), 2) ,0)) AS TotalUsed,
SUM(IF(i.name='Total Memory',TRUNCATE((tu.value_max) / (1024 * 1024 * 1024), 2) ,0)) AS TotalMemory
FROM
trends_uint tu
INNER JOIN items i
ON i.itemid = tu.itemid
INNER JOIN graphs_items gi
ON gi.itemid = i.itemid
INNER JOIN graphs g
ON g.graphid = gi.graphid
INNER JOIN HOSTS h
ON h.hostid = i.hostid
LEFT JOIN flip_linkutilisation.servercolumns sc
ON sc.ColumnDetails = g.name
WHERE
i.name IN ('Total Memory', 'Total Memory [Free]',
'Total Memory [used]')
GROUP BY sc.ReqColumns, i.hostid, i.name
) AS x
well我想这会解决你的问题吗?
注意我删除不必要的连接和列并减少读取次数
well i think this will solve your problem?
watch out i remove the unnecessary joins and columns and reduce the number of reads