我收到以下语句的ORA-00936: missing expression
错误CASE WHEN
。可能是由于rownum
?我试过LIMIT 1
也无济于事TOP 1
(但这不是 Oracle SQL 的事情)
基本上,CASE WHEN
下面的内容是在子查询返回多个值(v_date)时捕获并仅选择两个重复项之一。
SELECT DISTINCT
g.v_type AS Type,
g.f_group AS Group,
g.v_no AS Number,
g.v_date AS Date,
g.a_year AS Year,
CASE WHEN COUNT(SELECT DISTINCT v_date
FROM glv
WHERE v_type_reference = g.v_type AND v_no_reference = g.v_no AND g.com = com) = '1'
THEN (SELECT DISTINCT v_date
FROM glv
WHERE v_type_reference = g.v_type AND v_no_reference = g.v_no AND g.com = com)
ELSE (SELECT v_date
FROM glv
WHERE v_type_reference = g.v_type AND v_no_reference = g.v_no AND g.com = com AND rownum = 1)
END AS LLD
FROM glv g
WHERE g.a_year = '2015'