0

这是我的代码:

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 然后按日期过滤,然后对另一个相同但不同的日期。

提前致谢

4

1 回答 1

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
于 2012-08-15T10:18:36.663 回答