我正在尝试选择最不常见的值。例如,如果我的数据如下所示,
0810 - City 0810
0810 - City 0810
0810 - City 0810
0810 - City 0810
0810 - City 0810
0810 - City 0810
0810 - City 0810
0145 - London 0145
0900 - City2 0900
0900 - City2 0900
我想要结果0145 - London 0145
。
答案 0 :(得分:0)
您可能还有其他数据条件,但我非常确定以下内容正朝着正确的方向发展:
with my_tab as
(
select '0810 - City 0810' my_col from dual union all
select '0810 - City 0810' my_col from dual union all
select '0810 - City 0810' my_col from dual union all
select '0810 - City 0810' my_col from dual union all
select '0810 - City 0810' my_col from dual union all
select '0810 - City 0810' my_col from dual union all
select '0810 - City 0810' my_col from dual union all
select '0123 - Raleigh 0123' my_col from dual union all
select '0123 - Raleigh 0123' my_col from dual union all
select '0145 - London 0145' my_col from dual
)
, my_group as
(
select my_col, count(*) cnt
from my_tab
group by my_col
)
select my_col
from my_group
where cnt < (select max(cnt) from my_group)
;