0
有沒有一種方法可以重寫或優化此查詢?優化選擇案例查詢
SELECT
MIN(CASE WHEN id = '001' THEN value END) Col1,
MIN(CASE WHEN id = '002' THEN value END) Col2,
MIN(CASE WHEN id = '003' THEN value END) Col3,
MIN(CASE WHEN id = '004' THEN value END) Col4,
MIN(CASE WHEN id = '005' THEN value END) Col5,
MIN(CASE WHEN id = '006' THEN value END) Col6
FROM table
WHERE id IN (001, 002, 003, 004, 005, 006) and
DATE(from_unixtime(t_stamp/1000)) "2014-11-12"
AND
value > -5 OR value > 5
GROUP BY DATE(from_unixtime(t_stamp/1000)), HOUR(from_unixtime(t_stamp/1000)), MINUTE(from_unixtime(t_stamp/1000)) DIV 60
它以前工作正常,但我加了
AND
value > -5 OR value > 5
後停止執行,並且只是超時。 關於如何使這個查詢更快的任何建議?
====
更新,我跑了此查詢,並沒有關閉窗口,它沒有執行,但它的時間太長 Query took 323.0750 seconds.
哦哇,這有所作爲。但問題,我如何做到這一點,如果例如在第一個案例中選擇'MIN(CASE WHEN id ='001'THEN END END)Col1'我只希望它遵循where子句'value> -5',然後對第二種情況'MIN(CASE WHEN id ='002'THEN END END)Col2'我希望它遵循'value> -5'嗎? – hocuspocus31 2014-11-14 20:20:23