Yangang Wang Yangang Wang - 11 days ago 5
SQL Question

oracle sql error:distinct case

I am trying to select a distinct column from an oracle database,my code is:

select ID,distinct case when DM='ST1B' then MC else DM end from D_DZDY


but,it does not work.If i remove 'distinct',it works:
enter image description here

Anybody can help me with this problem?thanks a lot! :D

Answer

The syntax is select distinct. There is no distinct function or operator on a single column.

Perhaps you intend:

select distinct ID, (case when DM = 'ST1B' then MC else DM end)
from D_DZDY;

This will return distinct pairs of id and the case expression.

Comments