Error: View's SELECT Contains a Subquery in the FROM Clause
問題描述:
問題描述: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)原因:
根據 MySQL 文件,SELECT 語句不能在 FROM 子句中包含子查詢。
解決方案:# 创建包含子查询的视图: create view sum_credit_usage as select client_id, sum(credits_used) as credits_used from credit_usage group by client_id; # 创建您的最终视图: create view view_credit_status as (select credit_orders.client_id, sum(credit_orders.number_of_credits) as purchased, ifnull(sum_credit_usage.credits_used, 0) as used from credit_orders left outer join sum_credit_usage on t1.client_id = credit_orders.client_id where credit_orders.payment_status='Paid' group by credit_orders.client_id);您的解決方法是為每個子查詢建立視圖。然後,您可以從視圖 view_credit_status 中存取這些視圖。
以上是如何解決 MySQL 中的「視圖的 SELECT 在 FROM 子句中包含子查詢」錯誤?的詳細內容。更多資訊請關注PHP中文網其他相關文章!