0

我有这个查询

SELECT Calendar."Production Week" FROM Opex 
WHERE 
(
Calendar."Production Week" BETWEEN  VALUEOF("LAST_WEEK")-200 
AND  
VALUEOF("LAST_WEEK")
) 
OR 
(
(
(MOD(Calendar."Production Week", 100) = 1) 
OR 
(MOD(Calendar."Production Week", 100) = 13) 
OR 
(MOD(Calendar."Production Week", 100) = 26) 
OR 
(MOD(Calendar."Production Week", 100) = 39) 
OR 
(MOD(Calendar."Production Week", 100) = 52)   
)  
AND 
(Calendar."Production Week" <=
VALUEOF("LAST_WEEK"))
) 
ORDER BY Calendar."Production Week" DESC

那么我的问题是,是否有任何其他方法可以使此查询比它更短,尤其是 MOD 函数,因为它具有相同的结果 200639、200652、200713、2007 26、200739 等?提前致谢。

4

3 回答 3

1
MOD(Calendar."Production Week", 100) IN (1,13,26,39,52) 

够了吗?

于 2011-11-15T10:12:06.120 回答
0

您可以将 OR 链更改为 IN 子句

MOD(Calendar."Production Week", 100) in (1,13,26,39,52)
于 2011-11-15T10:12:43.047 回答
0
SELECT Calendar."Production Week" FROM Opex
WHERE (
     Calendar."Production Week" BETWEEN VALUEOF("LAST_WEEK")-200 AND VALUEOF("LAST_WEEK")
)
OR
(
     (
        (MOD(Calendar."Production Week", 100) in (1, 13, 26, 39, 52)
     )
     AND  (Calendar."Production Week" <= VALUEOF("LAST_WEEK"))
)
ORDER BY Calendar."Production Week" DESC
于 2011-11-15T10:14:06.830 回答