我正在尝试创建一个SQL查询,该查询将显示在vb.net中的Windows应用程序上,然后解压缩到excel文件中。我在SQL Server 2008中有两个表。下面是我的两个表的图像。
我想要实现的目标是:
但是在1个查询中执行此操作并包含Table2.Date。
我现在的2个问题是:
SELECT Table1.Id AS Z_Number,SUM(Table2.Amount) AS Cash_Payments, COUNT(Table2.TicketId)AS No_of_Tickets
FROM Table2,Table1
where Table2.Name='Cash' and Table2.Date between Table1.StartDate and Table1.EndDate and Table1.Id=1
GROUP BY Table1.Id
SELECT Table1.Id AS Z_Number,SUM(Table2.Amount) AS Credit_Card_Payments, COUNT(Table2.TicketId)AS No_of_Tickets
FROM Table2,Table1
where Table2.Name='Credit Card' and Table2.Date between Table1.StartDate and Table1.EndDate and Table1.Id=1
GROUP BY Table1.Id

关于我可以用什么确切的查询函数来实现它的任何建议?