开发者

How to correct sql syntax

开发者 https://www.devze.com 2023-01-07 09:08 出处:网络
I have 2 different table which is tbl_meter and tbl_machines. I am entering data using tbl_meter every day. I am finding dailiy results with following sql syntax. But I have problem with tbl_machines.

I have 2 different table which is tbl_meter and tbl_machines. I am entering data using tbl_meter every day. I am finding dailiy results with following sql syntax. But I have problem with tbl_machines. There is relation between 2 tables with local_no and machine_no fields. How can I fetch fileds from tbl_machines table and JOIN to tbl_meter table. I have already JOIN statement in first table. If anyone can help me I would be really appraciated. This is sql syntax that I am calculating results from tbl_meter. I would like to JOIN 2 fields from tbl_machines to 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.[Ma开发者_JAVA技巧chine_No] = B.[Machine_No] 
     WHERE A.[cDate] = @StartDate
       AND B.[cDate] = @EndDate;


You can join on multiple fields, e.g.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号