SSIS包查询-按查询计数

时间:2018-06-27 19:58:07

标签: ssis

我需要创建一个sis软件包来计算公司和承包商处理的订单数量。我的输入数据有与此相关的两列,如果两列都匹配,则表示按公司,否则按承包商。 输入表

enter image description here

如何获得基于此逻辑的计数?

我的输出应如下所示

enter image description here

请帮助。

1 个答案:

答案 0 :(得分:0)

以下方法将是一种实现方法- ssis包已将数据作为oledb的样本,然后将其传递到derived column进行列转换-请注意,输入和输出会有所不同,这就是我们需要派生列的原因。进行列转换后,我们将在行上执行所需的聚合。

包装布局- enter image description here

派生列- enter image description here

汇总- enter image description here

附带说明:我希望这些事情可以在数据库本身上执行-可以通过此简单查询完成-

;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