mysql view 子查询_mysql – View的SELECT包含FROM子句中的子查询

我有两个表,我需要创建一个视图.表格是:

credit_orders(id, client_id, number_of_credits, payment_status)

credit_usage(id, client_id, credits_used, date)

我使用以下查询来执行此操作.没有“创建视图”部分的查询运行良好,但使用“创建视图”时,它显示错误“视图的SELECT包含FROM子句中的子查询”.可能是什么问题&解决方案:

create view view_credit_status as

(select credit_orders.client_id,

sum(credit_orders.number_of_credits) as purchased,

ifnull(t1.credits_used,0) as used

from credit_orders

left outer join (select * from (select credit_usage.client_id,

sum(credits_used) as credits_used

from credit_usage

group by credit_usage.client_id) as t0

) as t1 on t1.client_id = credit_orders.client_id

where credit_orders.payment_status='Paid'

group by credit_orders.client_id)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值