我的问题是这样的

SELECT level1_idnt, day_dt, avg(sls_price) as avg_rp
FROM (SELECT * FROM (SELECT DISTINCT level1_idnt,day_dt,sls_price
                     FROM (SELECT a.level1_idnt,a.day_dt,a.sls_price,b.op
                           FROM (SELECT level1_idnt,day_dt,sls_price
                           FROM md1.loc_sku_dy_act_pos_full_v2
                           WHERE seasn_cd =2 and day_dt >= '2015-03-01 00:00:00' and day_dt <= '2015-09-30 00:00:00'
                                )l0
                           a left join (SELECT level1_idnt, AVG(org_sales_price) as op
                                        FROM (SELECT DISTINCT level1_idnt, org_sales_price
                                        FROM md1.item_lv1_org_price_m
                                        WHERE fr_cntry_cde = '01' AND org_sales_price IS NOT NULL
                                        ) l
                                        GROUP BY level1_idnt)l_op
                           b
                           ON a.level1_idnt = b.level1_idnt
                           )l1
            WHERE sls_price <= op
      )l2
      WHERE sls_price is not null
     ) l3
GROUP BY level1_idnt,day_dt;

为此我犯了个错误
syntax error at or near "a"

如有任何帮助,将不胜感激

最佳答案

选中此;)子查询中似乎有一个alias错误。

SELECT level1_idnt, day_dt, avg(sls_price) as avg_rp
FROM (SELECT * FROM (SELECT DISTINCT level1_idnt,day_dt,sls_price
                     FROM (SELECT a.level1_idnt,a.day_dt,a.sls_price,b.op
                           FROM (SELECT level1_idnt,day_dt,sls_price
                                 FROM md1.loc_sku_dy_act_pos_full_v2
                                 WHERE seasn_cd =2 and day_dt >= '2015-03-01 00:00:00' and day_dt <= '2015-09-30 00:00:00'
                                )
                          a left join (SELECT level1_idnt, AVG(org_sales_price) as op
                                       FROM (SELECT DISTINCT level1_idnt, org_sales_price
                                             FROM md1.item_lv1_org_price_m
                                             WHERE fr_cntry_cde = '01' AND org_sales_price IS NOT NULL
                                            ) l
                                       GROUP BY level1_idnt)
                    b
ON a.level1_idnt = b.level1_idnt
)l1
WHERE sls_price <= op
)l2
WHERE sls_price is not null
) l3
GROUP BY level1_idnt,day_dt;

a之前有一个字符串l0,在b之前有一个字符串l

10-01 10:11