我是否可以对指定的变量进行案例比较' YRSUMGTHAN75&#39 ;?当我尝试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'
答案 0 :(得分: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
如果这没有帮助,请使用虚拟表格和数据构建一个小人工示例,以清楚地说明您的问题。