我有一个查询,我想计算未结头寸 - 关闭(计算另一个表中的已关闭行)并排除所有0结果
SELECT Positions.[Req #], tblPositionList.PositionName,
Positions.[Opening Date], Positions.[Close Date],
Positions.Status, Count([OpenPosition]![Close Date]) AS Closed,
Positions.Openings AS Opened, [Opened]-[Closed] AS Remaining
FROM tblPositionList INNER JOIN (
Positions INNER JOIN OpenPosition ON Positions.[Req #] = OpenPosition.[Req #])
ON (tblPositionList.PositionID = Positions.PositionID) AND
(tblPositionList.PositionID = OpenPosition.PositionID)
GROUP BY Positions.[Req #], tblPositionList.PositionName, Positions.[Opening Date],
Positions.[Close Date], Positions.Status, Positions.Openings;
我想在Remaining字段中添加一个过滤器。
答案 0 :(得分:0)
谢谢你,@ user3728595,它完美无缺。 最后的脚本是
SELECT Positions.[Req #], tblPositionList.PositionName, Positions.[Opening
Date], Positions.[Close Date], Positions.Status, Count([OpenPosition]![Close
Date]) AS Closed, Positions.Openings AS Opened, Positions.Openings-
Count([OpenPosition]![Close Date]) AS Remaining
FROM tblPositionList INNER JOIN (Positions INNER JOIN OpenPosition ON
Positions.[Req #] = OpenPosition.[Req #]) ON (tblPositionList.PositionID =
Positions.PositionID) AND (tblPositionList.PositionID =
OpenPosition.PositionID)
GROUP BY Positions.[Req #], tblPositionList.PositionName, Positions.[Opening
Date], Positions.[Close Date], Positions.Status, Positions.Openings
HAVING (((Positions.Openings-Count([OpenPosition]![Close Date]))>0));