开发者

Generate report

I have a table 'TableA':

TableA_ID (int) Date (smalldatetime) Name (string)

and a table 'TableB' linked with TableA by TableA_ID: TableB_ID (int) TableA_ID (int) Description (string) Total (double)

I want to sum up the TableB 'Total' column between two dates (TableA 'Date开发者_C百科').


This should work:

SELECT SUM(b.total)
FROM tableB AS b
INNER JOIN tableA AS a ON a.tableA_ID = b.tableA_ID
WHERE a.date BETWEEN <start_date> AND <end_date>

Regards, Alin


What about:

SELECT SUM(B.Total)
  FROM TableB AS B JOIN TableA AS A ON B.TableA_ID = A.TableA_ID
 WHERE A.Date BETWEEN '<early-date>' AND '<later-date>';


This might help.

SELECT SUM(Total)
FROM TableA
JOIN TableB ON TableA.TableA_ID = TableB.TableA_ID
WHERE TableA.Date BETWEEN 'start date' AND 'end date'
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜