[英]MySQL View's SELECT contains a subquery in the FROM clause… help to rewrite?
[英]Mysql 5.6/5.7: View's SELECT contains a subquery in the FROM clause
MySql的创建视图:
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上不可用。 有什么建议吗? 谢谢。
编辑:该示例是一个测试用例。 实际情况是创建一个视图,该视图将Bar的一个记录变成该视图中的两个记录:
CREATE VIEW Foo as
select types.type, bar.value from
(select 8 as type UNION ALL select 9 as type) types, Bar bar
问题在于您正在使用从另一个查询中选择的查询进行查看。
因此,您应该简单地以不同的方式在视图中编写选择查询。
解:
查询:
select type from (select 8 as type UNION ALL select 9 as type) types;
与:
select 8 as type UNION ALL select 9 as type
因此创建一个视图:
CREATE VIEW Foo AS
select 8 as type UNION ALL select 9 as type;
是的,这是MySQL中的更改。
MySQL的早期版本不允许在存储的视图定义中使用内联视图(或MySQL术语中的派生表)。
就建议而言...在视图查询中似乎不需要内联视图。 除此之外,我在问是否需要...,就是需要存储的视图定义的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.