我想以某种方式在 CASE 语句中使用 NOT IN 术语,但出现语法错误。我想要的是在 T.Segment 列中没有出现某个数字(在本例中为 14)时设置 TribQin=0。
SELECT DISTINCT F.JDAY,
F.TL6 AS 'OriginalLayer',
CASE
WHEN 14 NOT IN T.Segment THEN 0
ELSE
(SELECT T.flow
FROM trib_data AS T
WHERE T.JDAY<=F.JDAY AND T.Segment=14 AND T.Year=2000
ORDER BY T.JDAY DESC LIMIT 1)
END AS 'TribQin'
FROM FlexGridLayers AS F
INNER JOIN trib_data AS T
ON T.Segment=F.Segment
WHERE F.Year=2000 AND F.Segment=14
ORDER BY F.JDAY;
我得到的错误是:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'T.Segment THEN 0
ELSE
(SELECT T.flow
FROM trib_data AS T
' at line 4