SQL 所选的非聚合值必须是关联组的一部分
SQL Selected non-aggregate values must be part of the associated group
我不明白我在这里缺少什么。在我看来,我似乎在 select 语句
中包含了每个非聚合值
SELECT TOP 5
f_ev2.Identifier,
AVG(f_ev2.Identifier) AS Identifier,
MIN(f_ev2.Event_dtm) AS Erster_PZ_Scan
FROM DB_DWH_MART_AKM_PLT.VW_F_EVENT f_ev2
INNER JOIN
(
SELECT
DISTINCT f_ev.AUFTRAGGEBER_EKP AS EKP
FROM DB_DWH_MART_AKM_PLT.VW_F_EVENT f_ev
WHERE f_ev.PROCESS_NO = 1075
) AS manifest_users
ON f_ev2.AUFTRAGGEBER_EKP = manifest_users.EKP
WHERE f_ev2.event_dtm BETWEEN (date -1) AND (date -10)
GROUP BY f_ev2.Identifier
HAVING (f_ev2.PROCESS_NO = 1 OR f_ev2.PROCESS_NO = 2)
为什么我得到
SQL Selected non-aggregate values must be part of the associated group
聚合后没有更多细节,即f_ev2.PROCESS_NO
.
您可以将条件移动到 WHERE
AND f_ev2.PROCESS_NO IN (1, 2)
或应用聚合函数,例如
HAVING MIN(f_ev2.PROCESS_NO IN (1, 2)
但是后面的条件总是return一个空结果集,Explain 会揭示一个无法满足的条件:
WHERE f_ev2.event_dtm BETWEEN (date -1) AND (date -10)
您必须切换日期:
WHERE f_ev2.event_dtm BETWEEN (current_date -10) AND (current_date -1)
我不明白我在这里缺少什么。在我看来,我似乎在 select 语句
中包含了每个非聚合值SELECT TOP 5
f_ev2.Identifier,
AVG(f_ev2.Identifier) AS Identifier,
MIN(f_ev2.Event_dtm) AS Erster_PZ_Scan
FROM DB_DWH_MART_AKM_PLT.VW_F_EVENT f_ev2
INNER JOIN
(
SELECT
DISTINCT f_ev.AUFTRAGGEBER_EKP AS EKP
FROM DB_DWH_MART_AKM_PLT.VW_F_EVENT f_ev
WHERE f_ev.PROCESS_NO = 1075
) AS manifest_users
ON f_ev2.AUFTRAGGEBER_EKP = manifest_users.EKP
WHERE f_ev2.event_dtm BETWEEN (date -1) AND (date -10)
GROUP BY f_ev2.Identifier
HAVING (f_ev2.PROCESS_NO = 1 OR f_ev2.PROCESS_NO = 2)
为什么我得到
SQL Selected non-aggregate values must be part of the associated group
聚合后没有更多细节,即f_ev2.PROCESS_NO
.
您可以将条件移动到 WHERE
AND f_ev2.PROCESS_NO IN (1, 2)
或应用聚合函数,例如
HAVING MIN(f_ev2.PROCESS_NO IN (1, 2)
但是后面的条件总是return一个空结果集,Explain 会揭示一个无法满足的条件:
WHERE f_ev2.event_dtm BETWEEN (date -1) AND (date -10)
您必须切换日期:
WHERE f_ev2.event_dtm BETWEEN (current_date -10) AND (current_date -1)