select cast(i.invoicedatetime as date) as Date, oi.DepartmentID, departmentname, SubDepartmentName, sum(Quantity*each*UnitPrice-o.DiscountAmount-i.DiscountAmount) as Sales
from InvoiceInfo i,
orderinfo o,
OrderItemInfo oi,
DepartmentInfo d,
SubDepartmentInfo s
where i.InvoiceID = o.InvoiceID
and o.orderid = oi.OrderID
and oi.DepartmentID = d.DepartmentID
and oi.SubDepartmentID = s.SubDepartmentID
and oi.departmentid in (@DepartmentID)
group by DepartmentName, SubDepartmentName, InvoiceDateTime, oi.DepartmentID
order by DepartmentName
以下是此报告的预览视图:
是否有办法让我们的用户可以运行报告并创建单个报告,但是每个部门组都在报告中组合在一起?我需要每组的总数。
答案 0 :(得分:0)
是的,当您查看报告时,请右键单击包含Department的列,如果这是您想要的。基于此创建新组。然后,您可以决定如何看待它们。如果要在每个组之后放置分页符,那么当它导出到excel时,它会将每个组放在不同的表上。这是一个很好的教程 https://msdn.microsoft.com/en-us/library/ms170712.aspx
要添加自定义组,请执行以下操作:
select cast(i.invoicedatetime as date) as Date, oi.DepartmentID, departmentname, SubDepartmentName, sum(Quantity*each*UnitPrice-o.DiscountAmount-i.DiscountAmount) as Sales
from InvoiceInfo i,
orderinfo o,
OrderItemInfo oi,
DepartmentInfo d,
SubDepartmentInfo s
,case when oi.DepartmentID in (1,12,2,8,14,18,22,28,39) then 'Photo'
when oi.DepartmentID in (13,20,24,30,44) then 'Press, Books, Albums'
when oi.DepartmentID in (23,29,36,43,48) then 'Inkjet' end 'CustomGroup'
where i.InvoiceID = o.InvoiceID
and o.orderid = oi.OrderID
and oi.DepartmentID = d.DepartmentID
and oi.SubDepartmentID = s.SubDepartmentID
and oi.departmentid in (@DepartmentID)
group by DepartmentName, SubDepartmentName, InvoiceDateTime, oi.DepartmentID
order by DepartmentName