有没有其他方法可以在oracle中跟踪查询

时间:2020-06-11 15:56:58

标签: sql oracle join select subquery

select 
    a.id,
    a.name,
    b.group,
    a.accountno, 
    (
        select ci.cardno 
        from taccount ac, tcardinfo ci 
        where ac.accountno = ci.accountno 
    ) as card_no 
from tstudent a, tgroup b 
where a.id = b.id

以及如何从(select ci.cardno from taccount ac,tcardinfo ci where ac.accountno = ci.accountno)或其他任何方式中选择多个字段

请注意,这不是两个查询(主查询和子查询)中的关系。子查询的值取决于主查询的数据。主查询是通过联接多个表的数据集,子查询也是通过联接多个表的数据集

1 个答案:

答案 0 :(得分:0)

本质上,您是在描述横向连接。从版本12开始在oracle中可用。

您的查询尚不清楚各列来自哪个表(我作了假设,可能需要检查),并且您似乎在子查询中缺少联接条件(我在该位置添加了问号) ...但是想法是:

select 
    s.id,
    s.name,
    g.group,
    s.accountno, 
    x.*
from tstudent s
inner join tgroup g on g.id = s.id
outer apply (
    select ci.cardno 
    from taccount ac
    inner join tcardinfo ci on ????
    where ac.accountno = s.accountno 
) x

然后您可以将更多列返回到子查询,然后将显示在结果集中。