select A,B,A||B from 表1
union all
select A,B,A||B from 表2

A B 拼接字段
a b ab
a c ac
a d ad
c d cd
c a ca
b a ba

oracle数据库，求解决方法

5个回答

`````` select * from SELECT 拼接字段 FROM 表 ORDER BY CASE WHEN CAST(PARSENAME(拼接字段,2) AS int) IS NULL THEN 1 ELSE 0 END,CAST(PARSENAME(拼接字段,2) AS int), PARSENAME(拼接字段,2) group by 拼接字段
``````

SELECT A,B,CONCAT(A,B) 拼接字段 FROM 表1 UNION ALL SELECT A,B,CONCAT(A,B) 拼接字段 FROM 表2 GROUP BY CONCAT(A,B) || CONCAT(B,A)

``````SELECT a,b,CONCAT(a,b) from A AS a
WHERE  CONCAT(a,b) not in (SELECT CONCAT(a1.b,a1.a) FROM A as a2)
``````

select distinct t.* from (
select A||B from 表1
union all
select reverse(A||B) from 表1
union all
select A||B from 表2
union all
select reverse(A||B) from 表2
) t

with tt as (
select A,B,A||B as C from t0 a where not exists (select 1 from t0 b where b.A||b.B=a.B||a.A)
union all
select A,B,A||B as C from t1 a where not exists (select 1 from t1 b where b.A||b.B=a.B||a.A))
select * from tt
minus
select * from tt group by A,B,C having count(1)>1
minus
select * from (select A,B,A||B as C from t0 union all select B,A,B||A as C from t1)
group by A,B,C having count(1)>1
minus
select * from (select B,A,B||A as C from t0 union all select A,B,A||B as C from t1)
group by A,B,C having count(1)>1