我需要创建一个sis软件包来计算公司和承包商处理的订单数量。我的输入数据有与此相关的两列,如果两列都匹配,则表示按公司,否则按承包商。 输入表
如何获得基于此逻辑的计数?
我的输出应如下所示
请帮助。
答案 0 :(得分:0)
以下方法将是一种实现方法-
ssis
包已将数据作为oledb的样本,然后将其传递到derived column
进行列转换-请注意,输入和输出会有所不同,这就是我们需要派生列的原因。进行列转换后,我们将在行上执行所需的聚合。
附带说明:我希望这些事情可以在数据库本身上执行-可以通过此简单查询完成-
;WITH CTE AS(
SELECT '6/20/2018' AS Date, 'XXX' AS Station, 'XXX' AS WorkLocation, 12345 AS AccountNo UNION ALL
SELECT '6/20/2018' AS Date, 'XXX' AS Station, 'YYY' AS WorkLocation, 12345 AS AccountNo UNION ALL
SELECT '6/20/2018' AS Date, 'XXX' AS Station, 'XXX' AS WorkLocation, 12345 AS AccountNo)
SELECT Date,AccountNo,SUM(CASE WHEN Station = WorkLocation THEN 1 END) AS Company,SUM(CASE WHEN Station != WorkLocation THEN 1 END) AS Contractor
FROM CTE
GROUP BY Date,AccountNo