这是我的代码:
SELECT DataBaseUser.Agents, Abs(Sum([NoPPI1])) AS [NoPPI-1], Abs(Sum([NoPPI2])) AS [NoPPI-2], Abs(Sum([NoPPI3])) AS [NoPPI-3], Abs(Sum([NoPPI4])) AS [NoPPI-4], Abs(Sum([NoPPI5])) AS [NoPPI-5], Abs(Sum([NoPPI6])) AS [NoPPI-6], Abs(Sum([NoPPI1])+Sum([NoPPI2])+Sum([NoPPI3])+Sum([NoPPI4])+Sum([NoPPI5])+Sum([NoPPI6])) AS TotalNoPPI
FROM DataBaseUser INNER JOIN MainData ON DataBaseUser.ID = MainData.AgentDropDown
GROUP BY DataBaseUser.Agents;
尝试使此查询起作用,基本上查询总结了每个销售代理的总NoPPI1到NoPPI6。我遇到的问题是我需要在NoPPI1上有一些过滤器,比如说这个月,然后NoPPI2是2个月前的日期过滤器。
这可能吗?
由于
更新
目前的结果如下:
Agents | NoPPI1 | NoPPI2 | NoPPI3 | NoPPI4 | NoPPI5 | NoPPI6 |
--------------------------------------------------------------
Ash | 34 | 32 | 17 | 12 | 4 | 1 |
Kate | 45 | 23 | 15 | 9 | 2 | 0 |
等.. |
控制日期的字段是NoPPIDate1等。
所以我想要实现的是:
NoPPI1需要求和,然后是abs,然后按日期过滤,然后对另一个进行过滤,但是日期不同。
提前致谢
答案 0 :(得分:0)
要做的第一件事是使用UNION查询规范化表。这将为您提供更多控制权:
SELECT Agent, "NoPPI1" As Description, NoPPI1 As NoPPI, NoPPI1Date As NoPPIDate
FROM Table
UNION
SELECT Agent, "NoPPI2" As Description, NoPPI2 As NoPPI, NoPPI2Date As NoPPIDate
FROM Table
<...>
然后您可以更轻松地选择:
SELECT Agent, Sum(NoPPI) FROM UnionQ
WHERE NoPPIDate=#2012/12/31#
GROUP BY Agent