我在 MS Access 上遇到了 SQL 问题。
问题是,我有:一个人可以重复的周数是在两个不同的部门,或销售渠道,区域经理姓名,或两者都在同一周内。
我想要的是?我想在我有更多金额的同一周内合计总入站金额等(有 70 种不同)..
太好了,设法做到了,但是,当确定的一周内创建的总入站数和创建的 SR 相等时,它会重复该周。我没有第三个值将其放在这里,也许使用第一个值,但我没有不知道怎么做..:/
任何人都知道如何管理它?
我的SQL如下,谢谢!
SELECT
Raw.[NT Login],
Raw.[Fiscal Week],
MaxDuplicate.[Manager Name],
MaxDuplicate.[Area Manager Name],
MaxDuplicate.[Sales Channel],
MaxDuplicate.Department,
Raw.[Fiscal Month Name],
Raw.[Fiscal Quarter],
MaxDuplicate.[Functional Name],
Raw.Location,
Raw.Partner,
MaxDuplicate.Queue,
MaxDuplicate.[Queue Status Desc],
Raw.[Sub Region],
Sum(Raw.[SRs Created]) AS [SRs Created],
Sum(Raw.[Total Inbounds]) AS [Total Inbounds],
Raw.[Weekly Lag]
FROM Raw
INNER JOIN
(SELECT Raw.[NT Login],
Raw.[Fiscal Week],
Raw.[Manager Name],
Raw.[Area Manager Name],
Raw.[Sales Channel],
Raw.Department,
Raw.[Functional Name],
Raw.Queue,
Raw.[Queue Status Desc]
FROM Raw
INNER JOIN
(SELECT
Raw.[NT Login],
Raw.[Fiscal Week],
MAX(Raw.[Total Inbounds]) AS [Total Inbounds],
MAX(Raw.[SRs Created]) AS [SRs Created]
FROM Raw
GROUP BY Raw.[NT Login], Raw.[Fiscal Week]) AS Max
ON Raw.[NT Login] = Max.[NT Login]
AND Raw.[Fiscal Week] = Max.[Fiscal Week]
WHERE
Raw.[Total Inbounds] = Max.[Total Inbounds]
AND Raw.[SRs Created] = Max.[SRs Created]) AS MaxDuplicate
ON Raw.[NT Login] = MaxDuplicate.[NT Login]
AND Raw.[Fiscal Week] = MaxDuplicate.[Fiscal Week]
GROUP BY Raw.[NT Login],
Raw.[Fiscal Week],
MaxDuplicate.[Manager Name],
MaxDuplicate.[Area Manager Name],
MaxDuplicate.[Sales Channel],
MaxDuplicate.Department,
Raw.[Fiscal Month Name],
Raw.[Fiscal Quarter],
MaxDuplicate.[Functional Name],
Raw.Location,
Raw.Partner,
MaxDuplicate.Queue,
MaxDuplicate.[Queue Status Desc],
Raw.[Sub Region],
Raw.[Weekly Lag]