我有兩個表。他們目前在Access 2010中,但最終會遷移到Microsoft SQL 2010 DBMS。一個叫做EmployeeWages,另一個叫TimeClock。 EmployeeWages包含員工ID,工資和生效日期。 TimeClock表具有員工ID,與員工相關的工資以及工資有效的日期。匹配一個表的條目與另一個表中的兩個日期之間的數據點
我需要做的是匹配僱員工作的正確工資。目前該表具有TimeIn和TimeOut字段。爲了簡單起見,在這個問題中,我已經計算了工作時間,但是如果我可以在一個查詢中獲得所有內容,那將非常棒。
EmployeeWage
----------------------------------------------------------------------
| EmployeeID | RecordNum | EffectiveDate | WorkType | Wage |
-+------------+-+-----------+-+---------------+-+----------+-+------+-
| 6240 | 1 | 1/18/13 | Line | 6 |
----------------------------------------------------------------------
| 6240 | 2 | 4/1/13 | Bench | 7 |
----------------------------------------------------------------------
| 6240 | 3 | 6/1/13 | Min | 7.35 |
----------------------------------------------------------------------
| 6240 | 4 | 6/23/13 | Bench | 5 |
----------------------------------------------------------------------
| 6240 | 5 | 6/24/13 | Bench | 6.25 |
----------------------------------------------------------------------
| 6240 | 5 | 6/25/13 | Bench | 7.25 |
----------------------------------------------------------------------
然後
TimeClock
--------------------------------------------------
| EmployeeID | WorkType | Work Date| Hours |
-+------------+-+----------+-+---------+-+------+-
| 6240 | Line | 6/22/13 | 5 |
--------------------------------------------------
| 6240 | Bench | 6/22/13 | 7 |
--------------------------------------------------
| 6240 | Bench | 6/23/13 | 5 |
--------------------------------------------------
| 6240 | Bench | 6/24/13 | 6.25 |
--------------------------------------------------
| 6240 | Min | 6/24/13 | 2 |
--------------------------------------------------
產生的匹配表應該像...
TimeClock
-----------------------------------------------------------
| EmployeeID | WorkType | Work Date| Hours | Wage |
-+------------+-+----------+-+---------+-+------+-+------+-
| 6240 | Line | 6/22/13 | 5 | 6 |
-----------------------------------------------------------
| 6240 | Bench | 6/22/13 | 6.25 | 7 |
-----------------------------------------------------------
| 6240 | Bench | 6/23/13 | 6 | 5 |
-----------------------------------------------------------
| 6240 | Bench | 6/24/13 | 5.5 | 6.25 |
-----------------------------------------------------------
| 6240 | Min | 6/24/13 | 2 | 7.35 |
-----------------------------------------------------------
任何幫助,使他們那裏我將不勝感激!
你需要在加入一個額外條件,否則會產生(部分)Carthesian產品。 – wildplasser