合并多个 Oracle 查询以生成一个结果
是否可以将以下查询作为一个查询来执行?
[代码]
select count(*) from tableA;
select count(*) from tableB;
select count(*) from tableC;
select count(*) from tableD;
[/代码]
即。结果是这样的
|TablA|TableB|TableC|TableD|
|50 |300 |30 |9|
谢谢
Is it possible to execute the following query as one query?
[code]
select count(*) from tableA;
select count(*) from tableB;
select count(*) from tableC;
select count(*) from tableD;
[/code]
ie. the result to be something like this
|TablA|TableB|TableC|TableD|
|50 |300 |30 |9|
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的
Yes
以下应该适用于任何 DBMS。
Following should work with any DBMS.
试试这个:
其中
one 作为(选择 count(1) 作为 counterA,1 作为 tableA 中的虚拟值),
两个为(选择 count(1) 作为 counterB,1 作为 tableB 中的虚拟值),
三个为(选择 count(1) 作为 counterC,1 作为 tableC 中的虚拟值),
四个为(选择 count(1) 作为 counterD,1 作为 tableD 中的虚拟变量)
从一、二、三、四中选择一.counterA、二.counterB、三.counterC、四.counterD,其中一.dummy = 二.dummy、二.dummy = 三.dummy、三.dummy = four.dummy;< /b>
try this:
with
one as (select count(1) as counterA, 1 as dummy from tableA),
two as (select count(1) as counterB, 1 as dummy from tableB),
three as (select count(1) as counterC, 1 as dummy from tableC),
four as (select count(1) as counterD, 1 as dummy from tableD)
select one.counterA, two.counterB, three.counterC, four.counterD from one, two, three, four where one.dummy = two.dummy and two.dummy = three.dummy and three.dummy = four.dummy;