如select a.id ,a.name,b.id,b.name from A a ,B b where a.id = b.aid
试过distinct ,但是distinct是所有的字段重复才会去重,我只是当a.id相同时去重,如何实现! a.id 是18位字符串!
期待指点!
8 个解决方案
#1
用group by行不行
#2
select * from
(
select a.id ,a.name,b.id bid,b.name bname,
row_number() over(partition by a.id order by rowid) r1
from A a ,B b
where a.id = b.aid
) t
where r1 = 1
(
select a.id ,a.name,b.id bid,b.name bname,
row_number() over(partition by a.id order by rowid) r1
from A a ,B b
where a.id = b.aid
) t
where r1 = 1
#3
select a.id ,max(a.name),max(b.id),max(b.name) from A a ,B b where a.id = b.aid
group by a.id
#4
select a.id ,max(a.name),max(b.id),max(b.name) from A a ,B b where a.id = b.aid
group by a.id
#5
select a.id ,b.id,max(a.name),max(b.name) from A a ,B b where a.id = b.aid
group by a.id, b.id
#6
select a.id ,max(a.name),max(b.id),max(b.name) from A a ,B b where a.id = b.aid
group by a.id
#7
可以这样
select a.id ,a.name,b.id,b.name from A a ,B b where a.id = b.aid
select distinct a.id,
(select a1.name from A a1 where a1.id = a.id and rownum = 1) as name1,
(select b1.name from B b1 where b1.id = b.id and rownum = 1) as name2
from A a, B b
where a.id=b.id
select a.id ,a.name,b.id,b.name from A a ,B b where a.id = b.aid
select distinct a.id,
(select a1.name from A a1 where a1.id = a.id and rownum = 1) as name1,
(select b1.name from B b1 where b1.id = b.id and rownum = 1) as name2
from A a, B b
where a.id=b.id
#8
select a.id ,max(a.name),max(b.id),max(b.name) from A a ,B b where a.id = b.aid
group by a.id
group by a.id
#1
用group by行不行
#2
select * from
(
select a.id ,a.name,b.id bid,b.name bname,
row_number() over(partition by a.id order by rowid) r1
from A a ,B b
where a.id = b.aid
) t
where r1 = 1
(
select a.id ,a.name,b.id bid,b.name bname,
row_number() over(partition by a.id order by rowid) r1
from A a ,B b
where a.id = b.aid
) t
where r1 = 1
#3
select a.id ,max(a.name),max(b.id),max(b.name) from A a ,B b where a.id = b.aid
group by a.id
#4
select a.id ,max(a.name),max(b.id),max(b.name) from A a ,B b where a.id = b.aid
group by a.id
#5
select a.id ,b.id,max(a.name),max(b.name) from A a ,B b where a.id = b.aid
group by a.id, b.id
#6
select a.id ,max(a.name),max(b.id),max(b.name) from A a ,B b where a.id = b.aid
group by a.id
#7
可以这样
select a.id ,a.name,b.id,b.name from A a ,B b where a.id = b.aid
select distinct a.id,
(select a1.name from A a1 where a1.id = a.id and rownum = 1) as name1,
(select b1.name from B b1 where b1.id = b.id and rownum = 1) as name2
from A a, B b
where a.id=b.id
select a.id ,a.name,b.id,b.name from A a ,B b where a.id = b.aid
select distinct a.id,
(select a1.name from A a1 where a1.id = a.id and rownum = 1) as name1,
(select b1.name from B b1 where b1.id = b.id and rownum = 1) as name2
from A a, B b
where a.id=b.id
#8
select a.id ,max(a.name),max(b.id),max(b.name) from A a ,B b where a.id = b.aid
group by a.id
group by a.id