我有以下表格 -
Table 1
id name hours
Table 2
id department project
以下是我正在运行的查询 -
SELECT id, name, department, TOTAL
FROM table1
WHERE hours='15' AND (id, department,TOTAL) IN
(SELECT id, department, count(*) AS TOTAL FROM table2
WHERE project is 'CS' and deparment IN ('cs', 'ece')
GROUP BY id, department HAVING count(*) > 1)
运行此查询时,我收到以下错误 -
ERROR 1054 (42S22): Unknown column 'department' in 'field list''
以下是我编写此查询的link。
我在这里做错了什么?
修改
注意 - 由于连接操作的时间复杂性,我不想使用连接。
示例
table1
id name hours
1 a 15
2 b 16
3 c 15
table2
id department project
1 cs cs
2 ece cs
3 cs cs
4 mech cs
Expected ouput -
id name department hours
1 a cs 15
2 c cs 15
答案 0 :(得分:1)
您从department
选择table 1
。我无法在department
中看到table 1
的任何字段名称。
当您尝试选择数据库中不存在的字段时,通常会显示Unknown column in 'field list'
。