Mysql 5.6/5.7 : View's SELECT contains a subquery in the FROM clause

标签 mysql ubuntu subquery create-view

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/

相关文章:

mysql - 序列化查询两个表

mysql - 如何向 Hive(0.13.1) 表插入数据?

mysql - 使用内连接和子查询后 MYSQL 查询变慢

sql - Access 查询中的多表 NOT EQUAL

sql - 相关子查询如何与 Exists 运算符一起使用?

php - 表单提交在 mysql 中显示空白条目

php - 在php中复制带有mysql数据的html页面

bash - 在 bash 中绕过过滤 "."和 "space"

laravel - laravel 存储文件夹的服务器权限重置

linux - sudo apt-get update 和 ownCloud