我的查询是打击,它给我一个错误


  每个派生表必须具有自己的别名


select payout+earning balance,ps.auto_rebuy
 from (
   select IFNULL((SELECT sum(pe.amount)  from package_earning pe WHERE pe.type in(0,1,3) and pe.create_date='1500332400' and pe.payment_to=1 GROUP BY pe.payment_to),0) as earning,
   IFNULL((SELECT p.app_id  from package_earning p WHERE p.type in(0,1,3) and p.create_date='1500332400' and p.payment_to=1 GROUP BY p.payment_to),0) as my_app_id,
   IFNULL((SELECT sum(pp.amount*(pd.payout/100))  from package_payout pp join package_payout_dates pd on pd.create_date between pp.start_date and pp.end_date WHERE pd.create_date = '1500332400' and app_id=1 GROUP BY app_id),0) as payout
 )
left join package_setting ps on ps.app_id=my_app_id

最佳答案

格式化后,有四个潜在的关注领域

SELECT payout+earning balance
     , ps.auto_rebuy
FROM (SELECT IFNULL((SELECT sum(pe.amount)
                     FROM package_earning pe
                     WHERE pe.type in(0,1,3)
                       and pe.create_date='1500332400'
                       and pe.payment_to=1
                     GROUP BY pe.payment_to) Z ,0) as earning          --I added the Z
           , IFNULL((SELECT p.app_id
                     FROM package_earning p
                     WHERE p.type in(0,1,3)
                       and p.create_date='1500332400'
                       and p.payment_to=1
                     GROUP BY p.payment_to)Y ,0) as my_app_id         -- I added the Y
           , IFNULL((SELECT sum(pp.amount*(pd.payout/100))
                     FROM package_payout pp
                     INNER JOIN package_payout_dates pd
                        on pd.create_date between pp.start_date and pp.end_date
                     WHERE pd.create_date = '1500332400'
                       and app_id=1 GROUP BY app_id) X,0) as payout    --I added the X
     )  A                                                              --I added the A
LEFT JOIN package_setting ps
  on ps.app_id=A.my_app_id


但我会认真考虑重构此查询

关于mysql - 从内部查询加入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45198012/

10-11 05:49