0

我可以对分配的变量“YRSUMGTHAN75”进行案例比较吗?当我尝试这样做时,case statement它对我说“'>'附近的语法不正确”。

这是我的 SQL:

SELECT A.DUR, A.TL_QUANTITY,
(SELECT SUM(TL_QUANTITY) FROM PS_TL_RPTD_TIME 
WHERE DUR BETWEEN '01-01-2013' AND '12-31-2013' AND EMPLID = A.EMPLID AND TRC IN   ('JNC', 'SRJ')
HAVING SUM(TL_QUANTITY) > 75) AS YRSUMGTHAN75 

CASE YRSUMGTHAN75 WHEN > 75 THEN 'NewValue'
End

FROM PS_TL_RPTD_TIME A WHERE  A.EMPLID = '10000106052' AND A.DUR > '01-01-2013'
4

1 回答 1

0

我不完全理解您要做什么,但这可能是:

select 
    DUR, 
    TL_QUANTITY, 
    case when YRSUMGTHAN75 > 75 then 'NewValue' else 'OldValue' end
from
    (
    SELECT 
        A.DUR, 
        A.TL_QUANTITY,
        (SELECT SUM(TL_QUANTITY) 
         FROM PS_TL_RPTD_TIME 
         WHERE DUR BETWEEN '01-01-2013' AND '12-31-2013' AND EMPLID = A.EMPLID AND TRC IN   ('JNC', 'SRJ')
         HAVING SUM(TL_QUANTITY) > 75) AS YRSUMGTHAN75 
    FROM 
        PS_TL_RPTD_TIME A 
    WHERE  
        A.EMPLID = '10000106052' AND A.DUR > '01-01-2013'
    ) dt

如果这没有帮助,请使用虚拟表和数据构建一个的人工示例,以清楚地说明您的问题。

于 2013-06-07T19:41:09.940 回答