我需要编写一个查询来生成一个结果,以便在其他OLD_ACCOUNT_ID
可用时显示NULL
,并在同一个表格中显示NEW_ACCOUNT_ID
时NULL
基于OLD
条件。我尝试了如下所示的查询,但这不会在NEW
和SELECT DISTINCT
A.ACCOUNT_ID as NEW_ACCOUNT_ID,
A.ACTIVE_FLAG,A.DATA_ID
FROM Table A
WHERE DATA_SOURCE_PROVIDER_ID='X'
AND ACTIVE_FLAG='Y'
and DATA_ID= '12345678'
union
SELECT DISTINCT B.ACCOUNT_ID AS OLD_ACCOUNT_ID,
B.ACTIVE_FLAG,B.DATA_ID
FROM Table B
WHERE DATA_SOURCE_PROVIDER_ID='X'
AND ACTIVE_FLAG='N'
and DATA_ID= '12345678'
的单独列中生成数据。有人可以帮忙吗。
map.values().removeAll(Collections.singleton(null));
答案 0 :(得分:1)
用例
select DISTINCT
case ACTIVE_FLAG when 'Y' then ACCOUNT_ID end as NEW_ACCOUNT_ID,
case ACTIVE_FLAG when 'N' then ACCOUNT_ID end as OLD_ACCOUNT_ID,
ACTIVE_FLAG,D
DATA_ID
from Table
whene DATA_ID= '12345678';