请参阅以下代码:
SELECT
mp_asin.CATEGORY_CODE AS Category_id
,mp_asin.SUBCATEGORY_CODE AS SUBCATEGORY
,mp_asin.PARENT_ASIN
,mp_asin.PARENT_ASIN_NAME
,mp_asin.COLOR_NAME AS Color_Name
,mp_asin.PRODUCT_SITE_LAUNCH_DAY AS PSLD
,mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME as TEEN
,mp_asin.BRAND_CODE AS Brand_Code
,mp_asin.REPLENISHMENT_CODE as REPLEN_CODE
,mp_asin.REPLENISHMENT_CATEGORY_ID AS Replen_TIER
,mp_asin.ASIN as ASIN
,MIN(mp.REPLENISHMENT_CODE) OVER (PARTITION BY (mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME)) as MIN_TEEN_RC
,MAX(mp.REPLENISHMENT_CODE) OVER (PARTITION BY (mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME)) as MAX_TEEN_RC
FROM
d_mp_asins mp_asin
WHERE
MIN_TEEN_RC <> MAX_TEEN_RC
AND mp_asin.CATEGORY_CODE =('30905500')
AND mp_asin.SUBCATEGORY_CODE =('30905560')
AND mp_asin.REGION_ID = 1
AND mp_asin.MARKETPLACE_ID = 1
AND mp_asin.GL_PRODUCT_GROUP = 309
我的错误似乎出现在Where
子句中。还有另一种写作方式
Min_Teen_RC <> MAX_TEEN_RC
我尝试了以下操作并得到了同样的错误:
MIN(mp.REPLENISHMENT_CODE) OVER (PARTITION BY (mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME)) <> MAX(mp.REPLENISHMENT_CODE) OVER (PARTITION BY (mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME))
以下是我遇到的错误:
ORA-00904:&#34; MAX_TEEN_RC&#34;:无效标识符
感谢您的帮助!
以下是V2的完整代码:
SELECT
mp_asin.CATEGORY_CODE AS Category_id
,mp_asin.SUBCATEGORY_CODE AS SUBCATEGORY
,mp_asin.PARENT_ASIN
,mp_asin.PARENT_ASIN_NAME
,mp_asin.COLOR_NAME AS Color_Name
,mp_asin.PRODUCT_SITE_LAUNCH_DAY AS PSLD
,mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME as TEEN
,mp_asin.BRAND_CODE AS Brand_Code
,mp_asin.REPLENISHMENT_CODE as REPLEN_CODE
,mp_asin.REPLENISHMENT_CATEGORY_ID AS Replen_TIER
,mp_asin.ASIN as ASIN
,MIN(mp.REPLENISHMENT_CODE) OVER (PARTITION BY (mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME)) as MIN_TEEN_RC
,MAX(mp.REPLENISHMENT_CODE) OVER (PARTITION BY (mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME)) as MAX_TEEN_RC
FROM
d_mp_asins mp_asin
WHERE
MIN(mp.REPLENISHMENT_CODE) OVER (PARTITION BY (mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME)) <> MAX(mp.REPLENISHMENT_CODE) OVER (PARTITION BY (mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME))
AND mp_asin.CATEGORY_CODE =('30905500')
AND mp_asin.SUBCATEGORY_CODE =('30905560')
AND mp_asin.REGION_ID = 1
AND mp_asin.MARKETPLACE_ID = 1
AND mp_asin.GL_PRODUCT_GROUP = 309
Group by
mp_asin.CATEGORY_CODE
,mp_asin.SUBCATEGORY_CODE
,mp_asin.PARENT_ASIN
,mp_asin.PARENT_ASIN_NAME
,mp_asin.COLOR_NAME
,mp_asin.PRODUCT_SITE_LAUNCH_DAY
,mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME
,mp_asin.BRAND_CODE
,mp_asin.REPLENISHMENT_CODE
,mp_asin.REPLENISHMENT_CATEGORY_ID
,mp_asin.ASIN
答案 0 :(得分:1)
试试这个 -
SELECT * FROM
(
SELECT
mp_asin.CATEGORY_CODE AS Category_id
,mp_asin.SUBCATEGORY_CODE AS SUBCATEGORY
,mp_asin.PARENT_ASIN
,mp_asin.PARENT_ASIN_NAME
,mp_asin.COLOR_NAME AS Color_Name
,mp_asin.PRODUCT_SITE_LAUNCH_DAY AS PSLD
,mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME as TEEN
,mp_asin.BRAND_CODE AS Brand_Code
,mp_asin.REPLENISHMENT_CODE as REPLEN_CODE
,mp_asin.REPLENISHMENT_CATEGORY_ID AS Replen_TIER
,mp_asin.ASIN as ASIN
,MIN(mp.REPLENISHMENT_CODE) OVER (PARTITION BY (mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME)) as MIN_TEEN_RC
,MAX(mp.REPLENISHMENT_CODE) OVER (PARTITION BY (mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME)) as MAX_TEEN_RC
FROM
d_mp_asins mp_asin
WHERE 1=1
AND mp_asin.CATEGORY_CODE =('30905500')
AND mp_asin.SUBCATEGORY_CODE =('30905560')
AND mp_asin.REGION_ID = 1
AND mp_asin.MARKETPLACE_ID = 1
AND mp_asin.GL_PRODUCT_GROUP = 309
)
where MIN_TEEN_RC <> MAX_TEEN_RC;
答案 1 :(得分:0)
使用有效的列名可以简单地避免ORA-00904 创建或更改语句。对于DML语句也可以是ORA-00904 通过对列名或别名进行有效引用来避免。
试试这个
SELECT * FROM
(
SELECT
mp_asin.CATEGORY_CODE AS Category_id
,mp_asin.SUBCATEGORY_CODE AS SUBCATEGORY
,mp_asin.PARENT_ASIN
,mp_asin.PARENT_ASIN_NAME
,mp_asin.COLOR_NAME AS Color_Name
,mp_asin.PRODUCT_SITE_LAUNCH_DAY AS PSLD
,mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME as TEEN
,mp_asin.BRAND_CODE AS Brand_Code
,mp_asin.REPLENISHMENT_CODE as REPLEN_CODE
,mp_asin.REPLENISHMENT_CATEGORY_ID AS Replen_TIER
,mp_asin.ASIN as ASIN
,MIN(mp.REPLENISHMENT_CODE) OVER (PARTITION BY (mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME)) as MIN_TEEN_RC
,MAX(mp.REPLENISHMENT_CODE) OVER (PARTITION BY (mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME)) as MAX_TEEN_RC
FROM
d_mp_asins mp_asin
) T
WHERE
T.MIN_TEEN_RC <> T.MAX_TEEN_RC
AND T.CATEGORY_CODE =('30905500')
AND T.SUBCATEGORY_CODE =('30905560')
AND T.REGION_ID = 1
AND T.MARKETPLACE_ID = 1
AND T.GL_PRODUCT_GROUP = 309
答案 2 :(得分:0)
您不能在WHERE子句中使用别名。您需要将组功能代码带到HAVING子句:
HAVING MIN(mp.REPLENISHMENT_CODE) OVER (PARTITION BY (mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME)) <>
MAX(mp.REPLENISHMENT_CODE) OVER (PARTITION BY (mp_asin.PARENT_ASIN_NAME || ', ' || mp_asin.COLOR_NAME))
但基本上,你的查询想法并不好。 GROUP BY不是必需的。