生成每日和每月销售报告

时间:2019-07-29 15:38:03

标签: sql-server vb.net crystal-reports

伙计们,

我在SQLSERVER 2016中有一个名为TblOrder_Details的表格,我想生成每日报告以显示Qty, Price, Amount,并且还需要汇总当天的销售总额,该表格应显示在所选天数范围内的其他天数

下面的代码是我尝试过的代码,但是当我使用SUM()聚合函数时仍然遇到问题,因为它确实只允许对一列进行分组

SELECT item_Name,qty, price, amount, Sum(amount) as Total_Amount 
FROM     tblOrderDetails  
where  Order_Date between @startdate and @enddate  GROUP BY Order_Date 

我正在将此报表放入Crystal报表中,但是它不显示结果。我尝试使用GROUP BY所选的所有列,而不呈现所需的方式。

输出应采用

的形式
OrderDate: 2019/07/29
item_Name   qty   price    amount
rice         2     2,000    4,000
beans        4     4,000    16,000


Summary
Total_qty=2
Total_AMount = 20,000

Order_Date:  2019/07/30
item_Name   qty   price    amount
soap         2     2,500    5,000
slippers     4     3,000    12,000


Summary
Total_qty=2
Total_Amount = 17,000

如果可能的话,我也可以生成月度销售额和年销售额,尤其是水晶报表的呈现

请帮助大家

1 个答案:

答案 0 :(得分:0)

要获得所需的输出,可以使用以下查询(每日报告):

SELECT  item_Name ,
        qty ,
        price ,
        amount ,
        Total_Amount,
        Order_Date 
FROM    tblOrderDetails T
        INNER JOIN ( SELECT SUM(amount) AS Total_Amount ,
                            Order_Date
                     FROM   tblOrderDetails
                     WHERE  Order_Date BETWEEN @startdate AND @enddate
                     GROUP BY Order_Date
                   ) D ON D.Order_Date = T.Order_Date
WHERE   Order_Date BETWEEN @startdate AND @enddate;