GROUP BY多个字段?

时间:2016-09-13 11:49:54

标签: reporting-services group-by

我想知道是否有人可以针对我的问题提供不同的帮助。

目前我所拥有的是:

SELECT
       [ItemDescription]
      ,COUNT(*) AS 'Amount'
FROM _shl_SalesOrderSummary ssos
WHERE ssos.[ItemDescription] 
       IN (SELECT [ItemDescription] FROM [_shl_SalesOrderSummary]
       WHERE ItemDescription LIKE '%FFP3 DUST MASK%' OR
       ItemDescription LIKE '%EAR DEFENDERS%' OR
       ItemDescription LIKE 'SAFETY GOGGLES'
       GROUP BY [ItemDescription])
GROUP BY ssos.[ItemDescription]

这给我带来了以下结果:

ItemDescription                          Amount
EAR DEFENDERS                             473
Ear defenders (helmet)                      1
FFP3 Dust masks (SPECIAL ORDER)             1
safety goggles                              1

我的问题是,我需要日期才能在报告中添加参数。

添加后,我似乎无法弄清楚如何正确实施它?

e.g:

SELECT TOP 50
       [Order Date]
      ,[ItemDescription]
      ,COUNT(*)
FROM _shl_SalesOrderSummary ssos
WHERE ssos.[ItemDescription] 
       IN (SELECT [ItemDescription] FROM [_shl_SalesOrderSummary]
       WHERE ItemDescription LIKE '%FFP3 DUST MASK%' OR
       ItemDescription LIKE '%EAR DEFENDERS%' OR
       ItemDescription LIKE '%SAFETY GOGGLES%'
       GROUP BY [ItemDescription])
GROUP BY ssos.[ItemDescription], ssos.[Order Date]

当日期按日期添加时,我的日期集会转为此,而不是上一个示例中的所有日期:

Order Date              ItemDescription Amount
2014-03-15 00:00:00      EAR DEFENDERS    15
2014-03-17 00:00:00      EAR DEFENDERS    10
2014-03-19 00:00:00      EAR DEFENDERS    22

任何指导或帮助将不胜感激 - 谢谢。

1 个答案:

答案 0 :(得分:1)

您的查询没问题。现在,您需要在ItemDescription字段

中对报表中的数据集进行分组

https://msdn.microsoft.com/en-us/library/dd255263.aspx