简体   繁体   English

SQL每日总计

[英]SQL Daily Totals

Ok so what I am trying to make is a ssrs report that gets daily totals of clients seen per employee and list that day by day. 好的,我想做的是一个ssrs报告,该报告获取每个员工每天看到的客户总数,并逐日列出。 So the top row would show every day in a month eg 1st ,2nd,3rd. 因此,第一行将显示一个月中的每一天,例如1st,2nd,3rd。 The first column should show the names of the employee. 第一列应显示员工姓名。

I'm pretty sure I nee to use a matrix to do this but am unsure how to go about this with listing out the days. 我很确定我需要使用矩阵来执行此操作,但是不确定如何列出日期。 If anyone can help me or point me in the right direction that would be great. 如果有人可以帮助我或指出正确的方向,那将是很好的。

To add more info I have a table called Employees with all the employees I want to list and a table appointments with all the clients that the employees have seen. 要添加更多信息,我有一个名为“雇员”的表,其中包含我要列出的所有雇员,以及一个表中有该雇员已看到的所有客户的约会。 I want to total the clients seen for each employee for every day of the month with the days listed across the top of the table. 我想将每个员工在每月的每一天看到的客户总数与表格顶部列出的天数相加。

for example 例如

      | 1st | 2nd | 3rd | 4th | 5th | 6th | 7th .....
emp1     2     3     5     4     5     5     6
emp2     3     4     5     9     1     3     5
emp3     1     0     0     4     5     9     2
emp4     8     3     7     2     9     3     4

If you want your rows to be columns, you need to use pivot like so: 如果要将行变成列,则需要使用数据透视,如下所示:

Example: 例:

SELECT VendorID, [250] AS Emp1, [251] AS Emp2, [256] AS Emp3, [257] AS Emp4, [260] AS Emp5
FROM 
(SELECT PurchaseOrderID, EmployeeID, VendorID
FROM Purchasing.PurchaseOrderHeader) p
PIVOT
(
COUNT (PurchaseOrderID)
FOR EmployeeID IN
( [250], [251], [256], [257], [260] )
) AS pvt
ORDER BY pvt.VendorID;

If you want your columns to be rows, you would use UNPIVOT. 如果您希望列为行,则可以使用UNPIVOT。

You are correct to use a matrix. 您正确使用矩阵。
Assuming you already have a query selecting the necessary information and joining properly: 假设您已经有一个查询,选择必要的信息并正确加入:
Create a Column Group, grouping by the appointment date. 创建一个列组,按约会日期分组。 Format your column header using Day(Fields!AppointmentDateTime.Value) to get the value from 1 to 31. 使用Day(Fields!AppointmentDateTime.Value)格式化列标题,以获取1到31之间的值。
Create a Row Group, grouping by Employee. 创建一个行组,按员工分组。 In the data cell, total the visits by using =Count(AppointmentDateTime.Value). 在数据单元格中,使用= Count(AppointmentDateTime.Value)总计访问次数。
If this report will span several months, include a parent column group where you group by Month(Fields!AppointmentDateTime.Value). 如果此报告将持续数月,请包括一个父列组,在其中按Month(Fields!AppointmentDateTime.Value)分组。 You can also add totals by right-clicking on a textbox in the row group and selecting "Add Total". 您也可以通过右键单击行组中的文本框并选择“添加总计”来添加总计。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM