0

我有 2 个不同的表,即 tbl_meter 和 tbl_machines。我每天都使用 tbl_meter 输入数据。我正在使用以下 sql 语法查找日常结果。但我对 tbl_machines 有疑问。具有 local_no 和 machine_no 字段的 2 个表之间存在关系。如何从 tbl_machines 表中获取文件并 JOIN 到 tbl_meter 表。我已经在第一个表中加入了 JOIN 语句。如果有人可以帮助我,我会非常感激。这是我从 tbl_meter 计算结果的 sql 语法。我想将 tbl_machines 的 2 个字段加入到 tbl_meter。

SELECT ((B.[turnover]*1) - (A.[turnover]*1)*1-((B.[total win]*1)*1 - (A.[total win]*1)*1)) As 'Result',
       A.[Machine_No] As 'Machine_No', (B.[turnover]*1) - (A.[turnover]*1) As 'Turnover', (B.[total win]*1) - (A.[total win]*1) As 'Total win',
       (B.[games played]*1) - (A.[games played]*1) As 'games played', 
       (B.[Credit In]*1) - (A.[Credit In]*1) As 'Credit In', 
       (B.[Bill In]*1) - (A.[Bill In]*1) As 'Bill In', 
       (B.[Cancel credit]*1) - (A.[Cancel credit]*1) As 'Cancel credit', 
       ((((B.[total win]*1)*1 - (A.[total win]*1)*1))*1 / ((B.[turnover]*1) - (A.[turnover]*1)*1))*1 As 'Actual%' 
  FROM tbl_meter A 
INNER JOIN tbl_meter B ON A.[Machine_No] = B.[Machine_No] 
     WHERE A.[cDate] = @StartDate
       AND B.[cDate] = @EndDate;
4

1 回答 1

1

您可以加入多个领域,例如

INNER JOIN tbl_machines MAC
ON MAC.local_no = A.local_no
AND MAC.machine_no = A.machine_no
于 2010-07-11T18:20:31.023 回答