使用Rails遷移(但並不重要)。我想在這裏創建一個視圖,但我得到了Mysql2 ::錯誤:視圖的SELECT在運行rails遷移時在FROM子句中包含子查詢
Mysql2::Error: View's SELECT contains a subquery in the FROM clause:
CREATE VIEW `lanciao` AS
當我試試這個:
create view lanciao as
select
subtime(payment.created_at, '0 5:0:0') as transaction_date,
`order_item`.total_quantity,
payment.amount as amount,
`order`.payment_type
from payments payment
join orders `order` on `order`.id = payment.order_id
left join donation_items donation on donation.order_id = `order`.id
inner join (
select order_id, sum(quantity) total_quantity
from order_items
group by order_id
) `order_item` on `order`.id = `order_item`.order_id
where payment.payment_state in ('settled', 'completed', 'captured', 'authorized', 'approved')
and `order`.fixed_order_id is null
沒有create view lanciao
,我可以運行select
塊到最後的罰款。我試圖重構這個,但不能得到它的工作。我應該如何解決這個問題?
我也意識到將這個分隔到不同的視圖並且互相引用,但我不會喜歡這種方式。
在另一個視圖中分隔每個子查詢。 – Melon 2015-04-01 10:24:51