문제

I have added "Monthbase" to my Time table. Now I want to add it to the Fact table. Using a left join:

 SELECT t1.[Posting_Date]
       ,t1.[Quantity]
       ,t1.[EmployeeID] --added afterwards
       ,t2.[Monthbase]
   FROM [Fact table] t1 LEFT JOIN [Time table] t2
     ON t1.[Posting_Date] = t2.[Posting_Date]

Monthbase

But I only want to see the value (8) one time per day, when applicable. The Time table has already been created with all requirements regarding holidays etc.

도움이 되었습니까?

해결책

Something like this:

;WITH CTE AS
(
  SELECT [EmployeeID],
        [Posting_Date]
       ,[Quantity]
       ,ROW_NUMBER() OVER (PARTITION BY [EmployeeID], [Posting_Date] ORDER BY [Quantity]) RN
   FROM [Fact table]
)
SELECT t1.[Posting_Date]
       ,t1.[EmployeeID]
       ,t1.[Quantity]
       ,CASE WHEN t1.RN = 1 THEN t2.[Monthbase] ELSE 0 END [Monthbase]
   FROM CTE t1
     LEFT JOIN [Time table] t2
       ON t1.[Posting_Date] = t2.[Posting_Date]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top