我有理由不断收到此错误吗? 错误:ORA-00933:SQL命令未正确结束 (州:S1000,土着代码:3A5)
对于此代码
SELECT DAY_DATE,
whse_prod_vendor_nbr,
PLN_NBR,
SUM(STOREIOH) "STORE IOH",
SUM(DCIOH) "DC IOH",
SUM(DCOO) "DC OO"
FROM (SELECT day_date, whse_prod_vendor_nbr, PLN_NBR, SUM(a.LO_IOH_UNITS) "STOREIOH"
FROM MSS_OWNER.FCT_IOH_DAY_STR_PLN a, dim_prod_pln b, dim_period c, dim_location d
WHERE a.prod_id = b.prod_id
AND a.per_id = c.per_id
AND a.loc_id = d.str_nbr
GROUP BY day_date, whse_prod_vendor_nbr, PLN_NBR
HAVING SUM(a.LO_IOH_UNITS) > 0) AS STORE
INNER JOIN (SELECT DAY_DATE, whse_prod_vendor_nbr, pln_nbr, SUM(a.TOT_REG_IOH_UNITS + a.TOT_DISTR_IOH_UNITS) "DCIOH", SUM(a.TOT_REG_ordr_UNITS + a.TOT_DISTR_ordr_UNITS) "DCOO"
FROM MSS_OWNER.FCT_DA_DAY_DC_VEND_WIC a, dim_prod_wic b, dim_period c
WHERE a.PROD_ID = b.PROD_ID
AND a.PER_ID = c.PER_ID
GROUP BY DAY_DATE, whse_prod_vendor_nbr, PLN_NBR
HAVING SUM(a.TOT_REG_IOH_UNITS + a.TOT_DISTR_IOH_UNITS) > 0) AS DC
ON STORE.PLN_NBR = DC.PLN_NBR
AND STORE.DAY_DATE = DC.DAY_DATE
Where DAY_DATE >= to_date ('1/26/2017', 'MM/DD/YYYY') --- ENTER THE DATE
AND DAY_DATE <= to_date('1/26/2017', 'MM/DD/YYYY') --- ENTER THE SAME DATE OR A RANGE
and PLN_NBR in ('40000278132')
--AND b.whse_prod_vendor_nbr in
GROUP BY DAY_DATE, whse_prod_vendor_nbr, PLN_NBR;
答案 0 :(得分:1)
在第7行的别名之前丢失了空格?
FROM (SELECT day_date, whse_prod_vendor_nbr, PLN_NBR, SUM(a.LO_IOH_UNITS) "STOREIOH"
另一件事是
AND (STOREIOH) > 0
这应该是
having SUM(a.LO_IOH_UNITS) > 0
在where子句中使用sum的问题与第二个子查询相同。在子查询别名中使用AS
还有一个问题。试试这个:
SELECT DAY_DATE,
whse_prod_vendor_nbr,
PLN_NBR,
SUM(STOREIOH) "STORE IOH",
SUM(DCIOH) "DC IOH",
SUM(DCOO) "DC OO"
FROM (SELECT day_date, whse_prod_vendor_nbr, PLN_NBR, SUM(a.LO_IOH_UNITS) "STOREIOH"
FROM MSS_OWNER.FCT_IOH_DAY_STR_PLN a, dim_prod_pln b, dim_period c, dim_location d
WHERE a.prod_id = b.prod_id
AND a.per_id = c.per_id
AND a.loc_id = d.str_nbr
GROUP BY day_date, whse_prod_vendor_nbr, PLN_NBR
HAVING SUM(a.LO_IOH_UNITS) > 0) STORE
INNER JOIN (SELECT DAY_DATE, whse_prod_vendor_nbr, pln_nbr, SUM(a.TOT_REG_IOH_UNITS + a.TOT_DISTR_IOH_UNITS) "DCIOH", SUM(a.TOT_REG_ordr_UNITS + a.TOT_DISTR_ordr_UNITS) "DCOO"
FROM MSS_OWNER.FCT_DA_DAY_DC_VEND_WIC a, dim_prod_wic b, dim_period c
WHERE a.PROD_ID = b.PROD_ID
AND a.PER_ID = c.PER_ID
GROUP BY DAY_DATE, whse_prod_vendor_nbr, PLN_NBR
HAVING SUM(a.TOT_REG_IOH_UNITS + a.TOT_DISTR_IOH_UNITS) > 0) DC
ON STORE.PLN_NBR = DC.PLN_NBR
AND STORE.DAY_DATE = DC.DAY_DATE
Where DAY_DATE >= to_date ('1/26/2017', 'MM/DD/YYYY') --- ENTER THE DATE
AND DAY_DATE <= to_date('1/26/2017', 'MM/DD/YYYY') --- ENTER THE SAME DATE OR A RANGE
and PLN_NBR in ('40000278132')
--AND b.whse_prod_vendor_nbr in
GROUP BY DAY_DATE, whse_prod_vendor_nbr, PLN_NBR