0

我在使用以下查询时遇到问题:

SELECT costingjobtimes.TimeStamp, costingdepartment.DeptDesc,  costingemployee.Name, costingjobtimes.TimeElapsed FROM costingemployee INNER JOIN (costingdepartment INNER JOIN costingjobtimes ON costingdepartment.DeptID = costingjobtimes.DeptID) ON costingemployee.EmployeeID = costingjobtimes.EmployeeID;

我希望它返回 costingjobtimes 数据库中的每一行,但它目前只返回 4。

基本上,我有 3 张桌子。(costingjobtimes, costingdepartment, costingemployee) 它们如下:

mysql> DESCRIBE costingemployee
    -> ;
+------------+------------+------+-----+---------+-------+
| Field      | Type       | Null | Key | Default | Extra |
+------------+------------+------+-----+---------+-------+
| EmployeeID | varchar(8) |      | PRI |         |       |
| Name       | text       |      |     |         |       |
+------------+------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> DESCRIBE costingdepartment
    -> ;
+----------+------------------+------+-----+---------+-------+
| Field    | Type             | Null | Key | Default | Extra |
+----------+------------------+------+-----+---------+-------+
| DeptID   | int(10) unsigned |      | PRI | 0       |       |
| DeptDesc | text             |      |     |         |       |
+----------+------------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> DESCRIBE costingjobtimes
    -> ;
+-------------+------------------+------+-----+---------------------+-----------
-----+
| Field       | Type             | Null | Key | Default             | Extra
     |
+-------------+------------------+------+-----+---------------------+-----------
-----+
| id          | int(10) unsigned |      | PRI | NULL                | auto_incre
ment |
| EmployeeID  | text             |      |     |                     |
     |
| DeptID      | int(10) unsigned |      |     | 0                   |
     |
| JobNumber   | text             |      |     |                     |
     |
| TimeElapsed | decimal(10,5)    |      |     | 0.00000             |
     |
| TimeStamp   | datetime         |      |     | 0000-00-00 00:00:00 |
     |
| JobRef      | text             |      |     |                     |
     |
+-------------+------------------+------+-----+---------------------+-----------
-----+
7 rows in set (0.00 sec)

所以所有的查询应该做的是从 costingjobtimes 返回所有的行,但是输入员工姓名而不是 EmployeeID 和部门描述而不是 DeptID。任何帮助都会很棒..

提前致谢,

4

1 回答 1

1

我不知道 Inner Join 是否真的是您正在寻找的 teishu。也许您应该尝试正常的加入。

例如:

select e.Name, d.DeptDesc, j.JobNumber, j.TimeElapsed, j.TimeStamp, j.JobRef
  from costingjobtimes as j
  join costingdepartment as d on d.DeptID = j.DeptId
  join costingemployee as e on e.EmployeeID = j.EmployeeID

这应该为您提供一个结果集,其中包含 costingjobtimes 表中的信息以及员工姓名和部门描述。

希望有帮助。

于 2009-11-24T10:54:40.137 回答