我有一个mysql查询,它使用union将多个查询连接到一个结果集中.查询工作得很好.
当我想使用相同的查询来创建视图时,我收到一条错误消息:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'union select hulaminloadnumber2,deliveryid,drop1customer from localjhb where hul' at line 2
Run Code Online (Sandbox Code Playgroud)
我的查询完美有效:
select hulaminloadnumber1,deliveryid,drop1customer from localjhb where hulaminloadnumber1>0
union
select hulaminloadnumber2,deliveryid,drop1customer from localjhb where hulaminloadnumber2>0
union
select hulaminloadnumber3,deliveryid,drop1customer from localjhb where hulaminloadnumber3>0
union
select hulaminloadnumber4,deliveryid,drop1customer from localjhb where hulaminloadnumber4>0
union
select hulaminloadnumber5,deliveryid,drop1customer from localjhb where hulaminloadnumber5>0
Run Code Online (Sandbox Code Playgroud)

我创建视图的查询是:
create view View_LoadvsCustomer as (
select hulaminloadnumber1,deliveryid,drop1customer from localjhb where hulaminloadnumber1>0
union
select hulaminloadnumber2,deliveryid,drop1customer from localjhb where hulaminloadnumber2>0
union
select hulaminloadnumber3,deliveryid,drop1customer from localjhb where hulaminloadnumber3>0
union
select hulaminloadnumber4,deliveryid,drop1customer from localjhb where hulaminloadnumber4>0
union
select hulaminloadnumber5,deliveryid,drop1customer from localjhb where hulaminloadnumber5>0)
Run Code Online (Sandbox Code Playgroud)
这会在PHPMyadmin中产生以下错误:

查询全部来自设计糟糕的表,因此不应存在格式化或排序规则问题.是否可以针对联合查询创建视图?
任何建议表示赞赏.
Ryan度过了一个愉快的周末