表1的最新數據:tblemployeeMYSQL:如何獲得table1的具體數據和獲得對錶2和表3
+------------+----------+-----------+-------+-------+
| 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
然而tblbadge
和tblemployeeactivity
不鏈接在一起也一樣在SQL中。
我得對tblemployee
員工的全部細節,並獲取每個表(tblbadge
& tblemployeeactivity
)的最新數據,請參見輸出計劃,TIA。
PS。我也有過濾
AttritionDate
由Year
和Month
'選擇一個*,b.BadgeNo,B。取消激活,b.ID_Rem,b.ID_S,c.ADate,c.AttritionDate,c.ID_AT FROM tblemployee a, (SELECT BadgeNo,Deactivation,ID_Rem,ID_S FROM tblbadge WHERE EmployeeID = a.EmployeeID ORDER BY Deactivation DESC LIMIT 1 )b , (SELECT ADate,AttritionDate,ID_AT FROM tblemployeeactivity WHERE EmployeeID = a.EmployeeID ORDER BY AttritionDate DESC LIMIT 1)c'可能不是最好的方法,但給一個鏡頭。 – Matt
SQLSTATE [42S22]:未找到列:1054'where子句'中的未知列'a.EmployeeID' 'a.EmpoyeeID'在where子句中未被識別 –