這裏是我的數據:如何獲取查詢以返回其中一行的前三個字符與另一行匹配的行?
with first_three as
(
select 'AAAA' as code from dual union all
select 'BBBA' as code from dual union all
select 'BBBB' as code from dual union all
select 'BBBC' as code from dual union all
select 'CCCC' as code from dual union all
select 'CCCD' as code from dual union all
select 'FFFF' as code from dual union all
select 'GFFF' as code from dual)
select substr(code,1,3) as r1
from first_three
group by substr(code,1,3)
having count(*) >1
該查詢返回滿足cirteria的字符。現在,我如何從中選擇以獲得理想的結果?或者,還有另一種方式嗎?
期望的結果
BBBA
BBBB
BBBC
CCCC
CCCD
http://sqlfiddle.com/#!4/3e0091/5 – Sai