mysql 创建视图 1349_mysql 创建视图出现1349 View's SELECT contains a subquery in the FROM clause解决办法...

习惯用oracle创建视图,最近在mysql下创建视图出现以下错误:

查询:CREATE or replace VIEW view_order_summary AS select a.opuser,a.audit_status,a.total,b.atotal,round(a.total/b.atotal,2) rate from...

错误代码: 1349

View's SELECT contains a subquery in the FROM clause

执行耗时   : 0 sec

传送时间   : 0 sec

总耗时      : 0.002 sec

原因是mysql不支持子查询,现解决办法就是把子查询分成多个视图,然后再把其它视图当表一样关联查询。

原出错语句:

CREATE OR REPLACE VIEW view_back_summary AS

SELECT a.opuser,a.audit_status,a.total,b.atotal,ROUND(a.total/b.atotal,2) rate FROM (

SELECT t.`OPUSER`,t.`AUDIT_status`,COUNT(1) total FROM back_form t GROUP BY t.`AUDIT_status`,t.`OPUSER`) a ,(

SELECT o.`OPUSER`,COUNT(1) atotal FROM back_form o GROUP BY o.`OPUSER`) b WHERE a.opuser = b.opuser;

修改后的语句:

CREATE VIEW view_back_1 AS

SELECT t.`OPUSER`,t.`AUDIT_status`,COUNT(1) total FROM back_form t GROUP BY t.`AUDIT_status`,t.`OPUSER`;

CREATE VIEW view_back_2 AS

SELECT o.`OPUSER`,COUNT(1) atotal FROM back_form o GROUP BY o.`OPUSER`;

CREATE OR REPLACE VIEW view_back_summary AS

SELECT a.opuser,a.audit_status,a.total,b.atotal,ROUND(a.total/b.atotal,2) rate FROM view_back_1 a, view_back_2 b WHERE a.opuser = b.opuser;

SELECT * FROM view_back_summary;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值