[英]creating summation in a sql table in SSIS for Tableau
我想在一個ssis包中按月總結每日日期的小時數。 我為此編寫了以下sql代碼:
下面的查詢計算ForecastHoursEnd的總和,然后按月對日期進行分組
select year(forecastdate) as y, month(forecastdate) as m,sum(ForecastHrsEnd) as p
from rpt_histsnapeng
group by year(forecastdate), month(forecastdate)
並且,以下查詢計算“實際小時數”總和,然后按月對日期進行分組
select year(ActualsDate) as y, month(ActualsDate) as m, sum(ActualHrs) as p
from rpt_histsnapeng
group by year(ActualsDate), month(ActualsDate)
現在,我試圖在SSIS中編寫代碼以將它們傳遞給變量/列,以便可以使用Tableau中的該列創建圖表,該怎么做?
為此,我引用了以下鏈接:
首先,完全沒有理由您不能僅使用Tableau來按年份和月份進行匯總-無需預先匯總數據。
但是,如果您堅持要首先使用SQL准備數據,則有兩種選擇:
1.聯盟
這是一種更規范的結構,將允許您使用t
(“類型”)作為度量來分離/描繪數據。
SELECT
YEAR(ForecastDate) AS y,
MONTH(ForcastDate) AS m,
'Forecast' AS t,
SUM(ForecastHrsEnd) AS p
FROM
rpt_histsnapeng
GROUP BY
YEAR(ForecastDate),
MONTH(ForcastDate)
UNION ALL
SELECT
YEAR(ActualsDate) AS y,
MONTH(ActualsDate) AS m,
'Actual' AS t,
SUM(ActualHrs) AS p
FROM
rpt_histsnapeng
GROUP BY
YEAR(ActualsDate),
MONTH(ActualsDate)
2.基本
這是非規范化的,更接近於現有的表結構。 通過簡單地將度量(小時)用作雙軸,Tableau也可以很好地處理此設計。
SELECT
YEAR(ForecastDate) AS Forecast_Year,
MONTH(ForcastDate) AS Forecast_Month,
YEAR(ActualsDate) AS Actual_Year,
MONTH(ActualsDate) AS Actual_Month,
SUM(ForecastHrsEnd) AS Forecast_Hours,
SUM(ActualHrs) AS Actual_Hours
FROM
rpt_histsnapeng
GROUP BY
YEAR(ForecastDate),
MONTH(ForcastDate),
YEAR(ActualsDate),
MONTH(ActualsDate)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.