表1:tblemployee
+------------+----------+-----------+-------+-------+
| EmployeeID | LastName | FirstName | ID_SC | ID_ES |
+------------+----------+-----------+-------+-------+
| 100000000 | Vallente | Rhea Mae | 7 | 2 |
+------------+----------+-----------+-------+-------+
| 100000001 | Margallo | Matt | 7 | 2 |
+------------+----------+-----------+-------+-------+
表2:tblbadge
+---------+------------+--------------+--------+------+
| BadgeNo | EmployeeID | Deactivation | ID_Rem | ID_S |
+---------+------------+--------------+--------+------+
| 1111111 | 100000001 | 2015-01-02 | 9 | 2 |
+---------+------------+--------------+--------+------+
| 2222222 | 100000001 | 2014-01-02 | 9 | 2 |
+---------+------------+--------------+--------+------+
表3:tblemployeeactivity
+------------+------------+---------------+-------+
| EmployeeID | ADate | AttritionDate | ID_AT |
+------------+------------+---------------+-------+
| 100000001 | 2015-01-01 | 2015-01-02 | 1 |
+------------+------------+---------------+-------+
| 100000001 | 2014-01-01 | 2014-01-02 | 1 |
+------------+------------+---------------+-------+
输出计划:
+------------+----------+-----------+-------+-------+---------+--------------+--------+------+------------+---------------+-------+
| EmployeeID | LastName | FirstName | ID_SC | ID_ES | BadgeNo | Deactivation | ID_Rem | ID_S | ADate | AttritionDate | ID_AT |
+------------+----------+-----------+-------+-------+---------+--------------+--------+------+-----------------------+----+-------+
| 100000001 | Margallo | Matt | 7 | 2 | 1111111 | 2015-01-02 | 9 | 2 | 2015-01-01 | 2015-01-02 | 1 |
+------------+----------+-----------+-------+-------+---------+--------------+--------+------+------------+---------------+-------+
问题:一个查询中最新的BadgeNo
和AttritionDate
如何假定tblemployee
与tblemployeeactivity
相关联,tblemployee
和tblbadge
相同{1}}但是tblbadge
和tblemployeeactivity
在SQL中没有链接在一起。
我必须在tblemployee
上获取员工的完整详细信息并获取每个表格的最新数据(tblbadge
& tblemployeeactivity
),请参阅输出计划,TIA。
PS。另外,我必须按
过滤AttritionDate
和Year
Month