所描述的表结构仅供参考。与数据库的列名不同。
我有一个相当不寻常的数据库。我有具有以下结构的代理表( Agents )。
A_ID(PK)| AgentName | Team
------------------------------------
1 | Abi | New
2 | Carl | New
3 | James | New
我有另外两个表,它们有几个字段,但有问题的表有......
表:交易
ID(PK) | manyColumns | Agent_ID | OUTCOME
--------------------------------------------------------
96 | ... | 1 | 9
98 | .... | 2 | 8
99 | ..... | 3 | 1
表:RAWDATA
ID(PK) | manyColumns | Agent_ID | BANK_OUTCOME
-------------------------------------------------------------
1234 | ... | 1 | 3
1114 | .... | 2 | 333
1745 | ..... | 3 | 123
我有一个记录表,其中包含员工工作时间的详细信息。
表:AGENT_ATTENDANCE
ATT_ID | Hours Worked | Agent_ID_FK
-------------------------------------------
96 | 7.5 | 1
98 | 7.5 | 2
99 | 7.5 | 3
我也有员工工资、合同工时的详细信息。
表:AGENT_DETAILS
DT_ID | Hours WK | Pay | Agent_ID_FK
-------------------------------------------------------
96 | 37.5 | 15600 | 1
98 | 37.5 | 15600 | 2
99 | 37.5 | 15600 | 3
我创建了单独的查询,但我想显示为一个..因为计算相互依赖..我不知道该怎么做..以下是单独的查询..我怎样才能将它们加入一个?
查询 - 1:
PARAMETERS [EnterStartDate:] DateTime, [EnterEndDate:] DateTime;
SELECT Agents.[Agent Name],
Sum(IIf((([TRANSACTIONS].[BankOutcome]=3) Or ([TRANSACTIONS].[BankOutcome]=333)),1,0)) AS PositiveOutcome,
Count(RAWDATA.Outcome) AS TotalRecordsUsed
FROM (RAWDATA LEFT JOIN Agents ON RAWDATA.[AGENT_ID] = Agents.A_ID) LEFT JOIN
TRANSACTIONS ON RAWDATA.ID = TRANSACTIONS.RAW_ID
WHERE (((RAWDATA.DialedDate) Between [EnterStartDate:] And [EnterEndDate:]))
GROUP BY Agents.[Agent Name], RAWDATA.AGENT_ID
HAVING (((RAWDATA.AGENT_ID) Is Not Null));
查询 - 2:
PARAMETERS [EnterStartDate:] DateTime, [EnterEndDate:] DateTime;
SELECT Agents.[Agent Name], AGENT_DETAILS.WK_TARGET_HOURS,
Sum(AGENT_ATTENDENCE.HoursWorked_Day) AS [Actual Hours Worked],
[WK_TARGET_HOURS]-[Actual Hours Worked] AS [Hours Lost], AGENT_DETAILS.SALARY,
Round([SALARY]/252/([WK_TARGET_HOURS]/5),2) AS [Hourly Rate], [Hourly Rate]*[Actual Hours Worked] AS [Staff Cost]
FROM (Agents INNER JOIN AGENT_DETAILS ON Agents.A_ID = AGENT_DETAILS.AGENT_ID_fk)
INNER JOIN AGENT_ATTENDENCE ON Agents.A_ID = AGENT_ATTENDENCE.AGENT_ID_fk
WHERE (((AGENT_ATTENDENCE.WorK_Date) Between [EnterStartDate:] And [EnterEndDate:]))
GROUP BY Agents.[Agent Name], AGENT_DETAILS.WK_TARGET_HOURS, AGENT_DETAILS.SALARY,
Agents.Active, Agents.Team
HAVING (((Agents.Active)=True) AND ((Agents.Team)<>"Manager" And (Agents.Team)<>"Cust. Ser."));
如果可以的话可以附上文件,但我不知道怎么做。