【问题标题】:Is there any alternative way for following query in oracle在 oracle 中跟踪查询是否有任何替代方法
【发布时间】:2020-10-01 08:02:09
【问题描述】:
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)或任何其他方式中选择多个字段

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

【问题讨论】:

  • 请提供样本数据和期望的结果。为什么不使用正确、明确、标准、可读的JOIN 语法?

标签: sql oracle join select subquery


【解决方案1】:

本质上,您是在描述横向连接。从版本 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

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

【讨论】:

  • 抱歉查询不完整,请让我完成查询
猜你喜欢
  • 2012-02-21
  • 1970-01-01
  • 2011-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多