不明确的 Mysql 列
Ambiguous Mysql Column
我有这个问题
SELECT t.employee_id, t.timeinhour,t.timeouthour,
SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(t.timeouthour, t.timeinhour))))
AS Duration FROM timesheets t
INNER JOIN employeetimesheets et
ON t.employee_id=et.employee_id
WHERE employee_id='6748372'
AND timeinyear='2017'
AND timeinmonth='March'
AND isWeekNumber='1'
它给我这个错误
1052 - Column 'employee_id' in where clause is ambiguous
我看过 here and here 但我没有使用 all (*)
所以我不明白为什么?
您要从中选择的表格的产品包括两个同名的列,如下所示:
ON t.employee_id=et.employee_id
timesheets
和 employeetimesheets
都有该列。由于 JOIN
子句将确保产品中的这两列始终具有相同的值,因此您指定哪一个可能并不重要。任何一个都可以完成这项工作:
WHERE t.employee_id='6748372'
尽管您可能希望对两者进行 运行 DESCRIBE
,看看性能是否有任何差异。
您必须指定您指的是哪个 table。试试这个,并注意更新的 WHERE
行:
SELECT t.employee_id, t.timeinhour,t.timeouthour,
SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(t.timeouthour, t.timeinhour))))
AS Duration FROM timesheets t
INNER JOIN employeetimesheets et
ON t.employee_id=et.employee_id
WHERE t.employee_id='6748372'
AND timeinyear='2017'
AND timeinmonth='March'
AND isWeekNumber='1'
你需要在 where
部分定义 table 别名,像这样
SELECT t.employee_id, t.timeinhour,t.timeouthour,
SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(t.timeouthour, t.timeinhour))))
AS Duration FROM timesheets t
INNER JOIN employeetimesheets et
ON t.employee_id=et.employee_id
WHERE t.employee_id='6748372'
AND t.timeinyear='2017'
AND t.timeinmonth='March'
AND t.isWeekNumber='1'
如果列来自 table employeetimesheets
设置 et
别名
我有这个问题
SELECT t.employee_id, t.timeinhour,t.timeouthour,
SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(t.timeouthour, t.timeinhour))))
AS Duration FROM timesheets t
INNER JOIN employeetimesheets et
ON t.employee_id=et.employee_id
WHERE employee_id='6748372'
AND timeinyear='2017'
AND timeinmonth='March'
AND isWeekNumber='1'
它给我这个错误
1052 - Column 'employee_id' in where clause is ambiguous
我看过 here and here 但我没有使用 all (*)
所以我不明白为什么?
您要从中选择的表格的产品包括两个同名的列,如下所示:
ON t.employee_id=et.employee_id
timesheets
和 employeetimesheets
都有该列。由于 JOIN
子句将确保产品中的这两列始终具有相同的值,因此您指定哪一个可能并不重要。任何一个都可以完成这项工作:
WHERE t.employee_id='6748372'
尽管您可能希望对两者进行 运行 DESCRIBE
,看看性能是否有任何差异。
您必须指定您指的是哪个 table。试试这个,并注意更新的 WHERE
行:
SELECT t.employee_id, t.timeinhour,t.timeouthour,
SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(t.timeouthour, t.timeinhour))))
AS Duration FROM timesheets t
INNER JOIN employeetimesheets et
ON t.employee_id=et.employee_id
WHERE t.employee_id='6748372'
AND timeinyear='2017'
AND timeinmonth='March'
AND isWeekNumber='1'
你需要在 where
部分定义 table 别名,像这样
SELECT t.employee_id, t.timeinhour,t.timeouthour,
SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(t.timeouthour, t.timeinhour))))
AS Duration FROM timesheets t
INNER JOIN employeetimesheets et
ON t.employee_id=et.employee_id
WHERE t.employee_id='6748372'
AND t.timeinyear='2017'
AND t.timeinmonth='March'
AND t.isWeekNumber='1'
如果列来自 table employeetimesheets
设置 et
别名