如何找到下面的查询如何找到一个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'你想要什么值?你并没有通过它进行聚合,你周围没有聚合功能。 –