MySql 创建 View :
CREATE VIEW Foo as
select type from (select 8 as type UNION ALL select 9 as type) types;
Windows 上的 MySql 5.7.11:工作,但 mysql 5.6.25-0ubuntu0.15.04.1 (Ubuntu):不工作。
View's SELECT contains a subquery in the FROM clause
这是从 5.6 到 5.7 的变化?我尝试在 Ubuntu 上将 mysql 升级到 5.7,但它在 Ubuntu 上不可用。有什么建议吗?谢谢。
编辑:这个例子是一个测试用例。实际情况是创建一个 View ,使 Bar 的一条记录成为 View 中的两条记录:
CREATE VIEW Foo as
select types.type, bar.value from
(select 8 as type UNION ALL select 9 as type) types, Bar bar
最佳答案
问题是您正在使用从另一个查询中选择的查询创建 View 。
所以你应该简单地在你的 View 中以不同的方式编写选择查询。
解决方法:
查询:
select type from (select 8 as type UNION ALL select 9 as type) types;
等同于:
select 8 as type UNION ALL select 9 as type
所以创建一个 View :
CREATE VIEW Foo AS
select 8 as type UNION ALL select 9 as type;
关于Mysql 5.6/5.7 : View's SELECT contains a subquery in the FROM clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40143771/