我想查詢從syslog嚴重/設施,並從號碼,然後轉化爲有意義的關鍵詞是這樣的:如何巧妙地在MySQL中創建鍵 - >值映射?
select case severity
when 0 then 'emerg'
when 1 then 'Alert'
when 2 then 'Crit'
when 3 then 'Error'
when 4 then 'Warn'
when 5 then 'Notice'
when 6 then 'Info'
when 7 then 'Debug'
end,
case facility
when 0 then 'kern'
when 1 then 'user'
...
when 23 then 'local7'
end
from logs.sys_log;
雖然嚴重性的範圍是從0到7,和設施的範圍是從0到23. 我會得到一個很長的查詢字符串。 是否有更聰明的方法來在MySQL中創建鍵 - >值映射來縮短查詢字符串?
[My] SQL與查詢字符串又有什麼關係?數據庫中的信息以及如何在URI資源中表示查詢是兩個不同的概念 - 儘管1:1映射通常使事情「更容易」保持順序。唯一的問題是確保在整個URI生命週期中穩定的密鑰,以免發生意外的交叉查詢。 – user2864740