我有一个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
我的查询完美无缺:
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
我创建视图的查询是:
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)
这会在PHPMyadmin中产生以下错误:
查询全部来自设计糟糕的表格,因此不应存在格式化或排序规则问题。是否可以针对联合查询创建视图?
感谢任何建议。
度过一个愉快的周末, 莱恩