我客人,對你的任務,如果你有員工具有比他應該在報告中包括2011年爲例2011-06-04結束日期。如果我是正確的,你需要SQL表達式像這樣的:
With Employee AS
(
SELECT 'employee1' as Name, '2010-02-01' as StartDate, '2012-04-01' as EndDate UNION ALL
SELECT 'employee2' as Name, '2010-02-01' as StartDate, '2011-04-01' as EndDate UNION ALL
SELECT 'employee3' as Name, '2010-02-01' as StartDate, '2011-04-01' as EndDate UNION ALL
SELECT 'employee4' as Name, '2011-02-01' as StartDate, '2012-04-01' as EndDate UNION ALL
SELECT 'employee5' as Name, '2011-02-01' as StartDate, '2012-04-01' as EndDate UNION ALL
SELECT 'employee6' as Name, '2011-02-01' as StartDate, '2012-04-01' as EndDate UNION ALL
SELECT 'employee7' as Name, '2011-02-01' as StartDate, '2012-04-01' as EndDate UNION ALL
SELECT 'employee8' as Name, '2012-02-01' as StartDate, '2012-04-01' as EndDate UNION ALL
SELECT 'employee9' as Name, '2012-02-01' as StartDate, '2012-04-01' as EndDate
)
SELECT Employee2.Name AS EmployeeName, YEAR(Employee.StartDate) AS EmployeeWorkedYear
FROM Employee
JOIN Employee as Employee2 ON YEAR(Employee2.EndDate) >= YEAR(Employee.StartDate) AND YEAR(Employee2.StartDate) <= YEAR(Employee.StartDate)
GROUP BY YEAR(Employee.StartDate), Employee2.Name
它會顯示在他工作的員工的名字和年份。然後,你應該創建一個這樣的表達(存儲過程)和組由第二列(年)數據集,並創建分組表,圖表等
可悲的是我是僅限於使用讀取。 – Hakan
我錯過了你提到關於獲取CRM,我沒有使用它,但快速的審查表明,你可以使用我的查詢,並與類似的方式獲取synatx創建相同的,它支持基於狀態ontities的鏈接(我客人它與Join相似)。 –