oracle plsql语句,有三张表联合查询,A表有id,name,grade,B表有pid,class,C表有tid,group,

2025-03-23 15:45:24
推荐回答(3个)
回答1:

你这个关键在于,

id在A表是否可能重复?           ---假设是不能重复的

pid在B表是否可能重复?         ---假设是能重复的,pid,class联合起来是不重复的

tid在C表是否可能重复?          ---假设是能重复的,tid,group联合起来是不重复的

select a.id,a.name,a.grade,bb.class,cc.group
from a,
(select pid,max(class) class from b group by pid) bb,
(select tid,max(group) group from c group by tid) cc
where a.id = bb.pid and a.id = cc.tid
  and A.id between 10 and 20

回答2:

select id,name,grade,class,group from A a,B b,C c where a.id between 10 and 20 and a.id = b.pid and a.id = c.tid;

回答3:

select distinct id,name,grade,class,group from A,B,C where id=pid and id=tid and id>=10 and id<=20