我试图统计过去七天内连续两天订购产品的次数。我试图在CASE WHEN中实现IN条件,但得到以下错误:Comparison operator IN not valid
我使用的是DB2
以下是我尝试过的方法:
WITH CTE AS (
SELECT ALLPIC, COUNT(DISTINCT(PAL.CODPRO)) AS NBREFSSTOCKS
FROM FGE50NEUV1.GEPAL AS PAL INNER JOIN FGE50NEUV1.GEPIC AS PIC ON PAL.CODPRO = PIC.CODPRO
GROUP BY ALLPIC
),
CTE2 AS (
SELECT ALLSTS AS ALLPIC, COUNT(DISTINCT CASE WHEN DATPRB1 = ` + dateWMS() + ` THEN CODPRO END) AS NBREFSCDE,
COUNT(
DISTINCT CASE WHEN (
CODPRO IN (SELECT DISTINCT(CODPRO) FROM FGE50NEUV1.GESUPD WHERE DATPRB1 = 20221027)
AND CODPRO IN (SELECT DISTINCT(CODPRO) FROM FGE50NEUV1.GESUPD WHERE DATPRB1 = 20221028)
THEN CODPRO END
)
) AS NBCOMMUNVEILLE,
COUNT(
DISTINCT CASE WHEN (
CODPRO IN (SELECT DISTINCT(CODPRO) FROM FGE50NEUV1.GESUPD WHERE DATPRB1 = 20221026)
AND CODPRO IN (SELECT DISTINCT(CODPRO) FROM FGE50NEUV1.GESUPD WHERE DATPRB1 = 20221027)
THEN CODPRO END
)
) AS NBCOMMUNJM2
FROM FGE50NEUV1.GESUPD AS SUP
GROUP BY ALLSTS
)
SELECT * FROM CTE INNER JOIN CTE2 ON CTE.ALLPIC = CTE2.ALLPIC ORDER BY CTE.ALLPIC
1条答案
按热度按时间xlpyo6sf1#
Listing of SQL messages:
数据库0115
比较运算符&1无效.
简单比较运算符(等于与不等于除外)不能与项列表一起使用. ANY,ALL与SOME比较运算符后面必须跟一个fullselect,而不能跟表达式或项列表.不能在JOIN条件或CASE表达式中指定子查询.
请更改比较或操作数。请重试请求。