我收到以下错误:
[Err] 1349 - View的SELECT包含FROM子句中的子查询
创建此视图时:
create view v_rescume_info as
select((case when goods.goods_fee is null then 0 else goods.goods_fee end)
+(case when rent.rent_fee is null then 0 else rent.rent_fee end)
+(case when baoxiao.baoxiao_fee is null then 0 else baoxiao.baoxiao_fee end))
as rescume_fee,goods.member_id from (select sum(product_price * product_quantity) as goods_fee,member_id from product_general_info group by member_id) goods
left join (select sum(house_fee + (case when water_fee is null then 0 else water_fee end)*water_price
+(case when electric_fee is null then 0 else electric_fee end)*electric_price) rent_fee,member_id from member_rent_info group by member_id) rent
on goods.member_id = rent.member_id
left join (select sum(finishedoff_price) as baoxiao_fee ,member_id from member_finishedoff_info group by member_id) baoxiao
答案 0 :(得分:0)
那太乱了。 为了帮助您,您可以使用合并
替换那些“当......然后”的情况 create view v_rescume_info as
select(
Coalesce(goods.goods_fee,0) + Coalesce(rent.rent_fee, 0) +
Coalesce(baoxiao.baoxiao_fee,0) as rescume_fee,
goods.member_id from v_newView1
为什么我把v_newView放在这里?嗯..你真的想从另一个选择中选择。你可以跨表,但它从来没有这样对我。这看起来像Transact-SQL而不是MySQL sintax。
在创建视图之前,请在外面测试这些视图。一旦你得到了结果,你就应该把“Create View foo as”。
对于我所看到的内容,您需要创建另一个视图“my”v_newView1,以便从子查询中获取结果。我建议你使用连接功能(左,右,内)来达到你想要的目的。
没有数据库,很难找出你的问题所在。调试时也使用多行。查看女巫线在哪里产生错误确实很有帮助。