2017-11-15 17 views
-2

行に表示されている値を取得するにはどうすればよいですか?1行にデータを照会する

SELECT 
h.host as 'Server', 
i.key_,max(x.clock), 
case when i.key_ like '%Total%' then x.value end as 'Total', 
case when i.key_ like '%free%' then x.value end as 'free', 
case when i.key_ like '%used%' then x.value end as 'used', 
x.itemid, 
x.value 
FROM `history_uint` as x 
left join items as i on x.itemid = i.itemid 
left join hosts as h on h.hostid = i.hostid 
Where i.key_ LIKE 'vfs.fs.size%' 
group by h.host 

これは、[選択で受け取っ1

Wanted

+1

サンプルデータは、あなたの問題を理解するのに役立つでしょう –

+0

こんにちは。あなたは明らかではありません。私はあなたが書いたものからあなたが望むものを理解できると思うとは信じられません。私はあなたが誰かがそれを読んで、あなたが望むものを推測することを期待していると信じています。それはコミュニケーションの方法ではありません。あなたの投稿を編集して、何を意味するのかを伝えてください。あなたはまた努力を示していません。 [ask]と[mcve]を読んで行動してください。 – philipxy

答えて

0

i.key_は無意味です私はこの瞬間 で受け取る出力である - それは不確定となり、あなたは条件付きの集約を必要とそうでない場合は、私の事おそらくこれのように。

SELECT 
h.host as 'Server', 
max(x.clock), 
sum(case when i.key_ like '%Total%' then x.value else 0 end) as 'Total', 
sum(case when i.key_ like '%free%' then x.value else 0 end) as 'free', 
sum(case when i.key_ like '%used%' then x.value else 0 end) as 'used', 
x.itemid, 
x.value 
FROM `history_uint` as x 
left join items as i on x.itemid = i.itemid 
left join hosts as h on h.hostid = i.hostid 
Where i.key_ LIKE 'vfs.fs.size%' 
group by h.host 
+0

iは内部結合です。言ってるだけ – Strawberry

関連する問題