我编写了一个可行的SQL查询,但是当我尝试将其翻译为查询Microsoft查询时,我在语法上遇到了很多问题。
这是我最初写的查询:
select
sum(PJC_FCTR_VL)
from
(select
max(PJC_FCTR_VL)
from
(select
R_CATEGORY_70075,
PRDC_KEY
from PRDC_DIM
where R_CATEGORY_70075 like '%RAMEN%')sub,
HS_PNLS_PJC_SBST_20150404 t1,
HSHLD_DIM t2,
HS_PRCH_SBST_20150404 t3
where
t1.PNLS_TYP_ID = 1
and t3.HSHLD_ID = t2.HSHLD_ID
and sub.PRDC_KEY = t3.PRDC_KEY
group by
t1.HSHLD_ID) subqry
我试图更多地打破这个问题,看看我搞砸了微软的查询,这就是我所得到的:
select
max(HS_PNLS_PJC_SBST_20150404.PJC_FCTR_VL)
from
{
PRDC_DIM.R_CATEGORY_70075, PRDC_DIM.PRDC_KEY
FROM AODR2QPNLSFWPR.ADMIN.PRDC_DIM PRDC_DIM
WHERE (PRDC_DIM.R_CATEGORY_70075 Like '%RAMEN%')} HS_PNLS_PJC_SBST_20150404
我最终得到一个错误,表示"期待OJ {"即使我没有真正做外连接。我想知道是否有人可以帮助我编辑SQL以使其满足Microsoft语法。
答案 0 :(得分:0)
尝试类似......
select sum(Max_PJC_FCTR_VL)
from
( select t1.HSHLD_ID, max(PJC_FCTR_VL) AS Max_PJC_FCTR_VL --<-- use two part name here
from ( select R_CATEGORY_70075,
PRDC_KEY
from PRDC_DIM
where R_CATEGORY_70075 like '%RAMEN%'
)sub
INNER JOIN HS_PRCH_SBST_20150404 t3 ON sub.PRDC_KEY = t3.PRDC_KEY
INNER JOIN HSHLD_DIM t2 ON t3.HSHLD_ID = t2.HSHLD_ID
INNER JOIN HS_PNLS_PJC_SBST_20150404 t1 ON t1.HSHLD_ID = t2.HSHLD_ID --<-- only guessing here
AND t1.PNLS_TYP_ID = 1
group by t1.HSHLD_ID
) subqry