搜尋
問答 這個where子句可以最佳化嗎?
這個where子句可以最佳化嗎?
P粉757640504 2024-04-01 16:12:46 查看 661

0

有人可以幫我解決這個問題嗎?我對以下功能有疑問;我可以為此創建一個虛擬專欄嗎?

select as1.col,as1.col2,as1.col3 from 
 analytics.adjusted_sale_velocity
 where 
      date(as1.created_datetime)=(
        select 
          max(
            date(created_datetime)
          )  
        from 
          analytics.adjusted_sale_velocity
      )

Your Answer
提交

1 個答案
0

一旦 WHERE 子句中的欄位以函數(在您的情況下為 date)包裝,MySQL 最佳化器將不會使用索引。

您的查詢可能會略有不同:

select as1.col,
       as1.col2,
       as1.col3 
from  adjusted_sale_velocity a
inner join ( select  max(created_datetime) as created_datetime   
             from adjusted_sale_velocity
            ) as max_dt on left(a.created_datetime,10) = left(max_dt.created_datetime,10) ;

嘗試讓我知道它是否更快。

2024-04-02 13:27:50

提交

Hot Tools

vc9-vc14(32+64位元)運行庫合集(連結在下方)

vc9-vc14(32+64位元)運行庫合集(連結在下方)

phpStudy安裝所需運行函式庫集合下載

VC9 32位

VC9 32位

VC9 32位元 phpstudy整合安裝環境運行庫

php程式設計師工具箱完整版

php程式設計師工具箱完整版

程式設計師工具箱 v1.0 php整合環境

VC11 32位

VC11 32位

VC11 32位元 phpstudy整合安裝環境運行庫

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用