一条Oracle语句,报错了,求大侠们改下。。。
SELECT S.NO 学号,
CASE
WHEN S.ID = '1210527501' THEN
(SELECT DATE
FROM STU
WHERE ID = '1210527501') AS 时间1,
WHEN S.ID = '1210527502' THEN
(SELECT DATE
FROM STU
WHERE ID = '1210527502') AS 时间2,
WHEN S.ID = '1210527503' THEN
(SELECT DATE
FROM STU
WHERE ID = '1210527503') AS 时间3,
ELSE
END
FROM STU S
WHERE S.NO LIKE '1240156742010%';
报红色部分缺失关键字。。。
[最优解释]
語法錯誤了吧
你想表達的是這樣吧:
SELECT S.NO 学号,
(SELECT TOP 1 DATE
FROM STU
WHERE ID = S.ID AND S.ID = '1210527501') AS 时间1,
(SELECT TOP 1 DATE
FROM STU
WHERE ID = S.ID AND S.ID = '1210527502') AS 时间2,
(SELECT TOP 1 DATE
FROM STU
WHERE ID = S.ID AND S.ID = '1210527503') AS 时间3
FROM STU S
WHERE S.NO LIKE '1240156742010%';
SELECT S.NO 学号,
CASE
WHEN S.ID = '1210527501' THEN
(SELECT TOP 1 DATE
FROM STU
WHERE ID = '1210527501')
WHEN S.ID = '1210527502' THEN
(SELECT TOP 1 DATE
FROM STU
WHERE ID = '1210527502')
WHEN S.ID = '1210527503' THEN
(SELECT TOP 1 DATE
FROM STU
WHERE ID = '1210527503') AS 时间
ELSE
END
FROM STU S
WHERE S.NO LIKE '1240156742010%';
--case when ... else ... end 是一个整体,在最外层才加别名
SELECT S.NO 学号,
(CASE
WHEN S.ID = '1210527501' THEN
(SELECT DATE
FROM STU
WHERE ID = '1210527501')
WHEN S.ID = '1210527502' THEN
(SELECT DATE
FROM STU
WHERE ID = '1210527502')
WHEN S.ID = '1210527503' THEN
(SELECT DATE
FROM STU
WHERE ID = '1210527503')
ELSE
END) as 时间
FROM STU S
WHERE S.NO LIKE '1240156742010%';