select case count(currentprice) when 60 then round(avg(currentprice),2) else 0 end as avg60 from (select currentprice from stocks where stockcode = '600795' order by closedate desc limit 803, 60) as t
計算均線資料,太慢了,limit 后面的數越大越慢。。
uj5u.com熱心網友回復:
那么復雜的查詢,是否一定需要實時扔給資料庫計算。可以考慮后臺定期計算,然后把結果保存。需要的時候直接從已有結果拿資料。uj5u.com熱心網友回復:
select currentprice from stocks where stockcode = '600795' order by closedate desc limit 803, 60慢在這句。得想法優化這陳述句。
uj5u.com熱心網友回復:
表結構什么的有嗎?uj5u.com熱心網友回復:
你的stocks表是分庫表么,是的話 查詢時候把分庫鍵條件加上,你這stocks應該是庫存表數量肯定大,這樣掃全表絕對是慢的轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/92431.html
標籤:MySQL
上一篇:sql陳述句優化問題,求助
