如何找到下面的查詢如何找到一個select查詢
select msgType
, max(loggedDate)
, interfaceName
from LOG_Hl7
where direction = 'INCOMING'
group
by msgType
HAVING msgType IN ('ADT');`
如何找到下面的查詢如何找到一個select查詢
select msgType
, max(loggedDate)
, interfaceName
from LOG_Hl7
where direction = 'INCOMING'
group
by msgType
HAVING msgType IN ('ADT');`
首先,編寫查詢爲:
select msgType, max(loggedDate), interfaceName
from LOG_Hl7
where direction = 'INCOMING' and msgType = 'ADT'
group by msgType;
即過濾器之前的聚合,而不是之後。
然後最好的索引是LOG_H17(direction, msgType, loggedDate)
。
interfaceName
只是掛在SELECT
條款。 MySQL允許它,但是你將從任何匹配WHERE
子句的行獲得任意值。
我更正了查詢,並且我需要在應用程序中爲我的業務目的使用interfaceName(接口名稱與ADT或RDE類似,可能會重複)。 – user1654352
要回答標題,請參閱我的Indexing Cookbook。
要解決您的特定查詢,請按照Gordon的建議重新編寫查詢並使用其建議的索引。還處理懸掛interfaceName
。
嗯......你的情況在我的食譜中缺失。建立從
=
零件WHERE
指數:以任何順序GROUP BY
,如食譜說direction
和msgType
。但msgType
已經在那裏。但它需要是最後的(到目前爲止) - 食譜中缺少這個註釋。
您的查詢格式錯誤。 ''interfaceName'你想要什麼值?你並沒有通過它進行聚合,你周圍沒有聚合功能。 –