如何用pl⼀sql查询多表的数据

2025-03-23 05:39:14
推荐回答(2个)
回答1:

select t1.公司代码,
       T1.公司名称,
       t3.行业名称,
       T2.次行业名称01,
       T2.次行业名称02,
       T2.次行业名称03
   from t1
   left join t2
   on t2.公司代码 = t1.公司代码
   left join t3
   on t3.行业代码 =t1.主行业代码
   where t2.次行业名称01 in ('6100','6200')
    or t2.次行业名称02 in ('6100','6200')
    or t2.次行业名称03 in ('6100','6200')
    or t1.主行业代码 in ('6100','6200')

回答2:

select t1.企业代码,t1.企业名称,t1.主行业代码,
              (select t3.行业名称 from t3 where t1.主行业代码 = t3.行业代码) 行业名称,
            (select t3.行业名称 from t3 where t2.次行业01代码 = t3.行业代码) 次行业01名称,
          (select t3.行业名称 from t3 where t2.次行业02代码 = t3.行业代码) 次行业02名称,
          (select t3.行业名称 from t3 where t2.次行业03代码 = t3.行业代码) 次行业03名称
from t1,t2
where t1.企业代码 = t2.企业代码
  and (t1.企业代码 in ('6100','6200') or t2.次行业01代码 in ('6100','6200')  or t2.次行业02代码 in ('6100','6200') or t2.次行业03代码 in ('6100','6200'))