我写了一个 sql 来从 Mysql 中的两个表中选择记录:
select * from(
select
IFNULL(a.father_id,0) as afi,
IFNULL(b.father_id, 0) as bfi,
IFNULL(a.id,0) AS aid,
IFNULL(b.id,0) AS bid,
a.competitor AS competitor,
IFNULL(a.merchant_order_no,b.merchant_order_no) AS order_no,
IFNULL(a.income,0) AS yingshou,IFNULL(b.income ,0) AS shishou,IFNULL(b.expenditure,0) AS shouxufei,a.apply_time AS apply_time,a.pay_time AS pay_time,b.trading_date AS trading_date,
IFNULL(a.trading_channel,b.trading_channel) as channel,
a.race_id,
a.group_id
from (azim_raceapplicant_export_xls a left join azim_finance_export_xls b on(a.merchant_order_no = b.merchant_order_no ))
union
select
IFNULL(a.father_id,0) as afi,
IFNULL(b.father_id, 0) as bfi,
IFNULL(a.id,0) AS aid,
IFNULL(b.id,0) AS bid,
a.competitor AS competitor,
IFNULL(a.merchant_order_no,b.merchant_order_no) AS order_no,
IFNULL(a.income,0) AS yingshou,IFNULL(b.income ,0) AS shishou,IFNULL(b.expenditure,0) AS shouxufei,a.apply_time AS apply_time,a.pay_time AS pay_time,b.trading_date AS trading_date,
IFNULL(a.trading_channel,b.trading_channel) as channel,
a.race_id,
a.group_id
from (azim_raceapplicant_export_xls a right join azim_finance_export_xls b on(a.merchant_order_no = b.merchant_order_no ))
)
as t
where afi=0 and bfi=0;
当我想为这个结果创建视图时,我得到了这个错误,当我搜索时,我知道视图中的子查询是限制的。
现在我可以做的是使用两个视图来获得这个结果。
所以我想知道如何在没有子查询的情况下重写这个sql??