当试图使用视图来查找有关数据库中表的信息时,我似乎无法在select语句中使用视图。
CREATE VIEW Num_projects AS SELECT ENumber, COUNT(*) AS Projects FROM WorksOn Group BY ENumber;
SELECT * FROM Num_projects;
CREATE VIEW Same_num_projects AS SELECT Employee.ENumber, Name FROM Employee JOIN Num_Projects WHERE Projects IN( SELECT Projects FROM Num_projects WHERE ENumber = 00101);
SELECT * FROM Same_num_projects;
这是处理上述代码的输出:
--------------
CREATE VIEW Same_num_projects AS SELECT Employee.ENumber, Name FROM Employee JOIN Num_Projects WHERE Projects IN( SELECT Projects FROM Num_projects WHERE ENumber = 00101)
--------------
ERROR 1146 (42S02): Table 'csit115.Num_Projects' doesn't exist
--------------
SELECT * FROM Same_num_projects
--------------
ERROR 1146 (42S02): Table 'csit115.Same_num_projects' doesn't exist
--------------
为什么我的观点没有被认可?
2条答案
按热度按时间mzmfm0qo1#
这是通过改变
JOIN Num_Projects
至JOIN Num_projects
gfttwv5a2#
它不区分大小写。创建第二个视图时未定义连接条件,缺少此条件
ON Employee.ENumber = Num_Projects.ENumber
. 如果没有on条件,就不能形成内部联接。