如何更正sql语法

时间:2010-07-11 18:12:19

标签: sql vistadb

我有两个不同的表,即tbl_meter和tbl_machines。我每天都使用tbl_meter输入数据。我正在使用以下sql语法找到dailiy结果。但我对tbl_machines有问题。 2个表与local_no和machine_no字段之间存在关系。如何从tbl_machines表和JOIN到tbl_meter表获取文件。我在第一个表中已经有JOIN语句。如果有人可以帮助我,我会真的被贬低。这是sql语法,我正在计算tbl_meter的结果。我想从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;

1 个答案:

答案 0 :(得分:1)

您可以加入多个字段,例如

INNER JOIN tbl_machines MAC
ON MAC.local_no = A.local_no
AND MAC.machine_no = A.machine_no