合并多个 Oracle 查询以生成一个结果

发布于 2024-11-05 17:58:17 字数 304 浏览 1 评论 0原文

是否可以将以下查询作为一个查询来执行?

[代码]

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

才能让你更想念 2024-11-12 17:58:17
select * from
(select count(*) from tableA),
(select count(*) from tableB),
(select count(*) from tableC),
(select count(*) from tableD);
select * from
(select count(*) from tableA),
(select count(*) from tableB),
(select count(*) from tableC),
(select count(*) from tableD);
通知家属抬走 2024-11-12 17:58:17

是的

select count(*) from tableA;
union all
select count(*) from tableB;
union all
select count(*) from tableC;
union all
select count(*) from tableD; 

Yes

select count(*) from tableA;
union all
select count(*) from tableB;
union all
select count(*) from tableC;
union all
select count(*) from tableD; 
香橙ぽ 2024-11-12 17:58:17

以下应该适用于任何 DBMS。

SELECT *
FROM   (select count(*) as tableA from tableA) a
       full outer join (select count(*) as tableB from tableB) b
       full outer join (select count(*) as tableC from tableC) c
       full outer join (select count(*) as tableD from tableD) d

Following should work with any DBMS.

SELECT *
FROM   (select count(*) as tableA from tableA) a
       full outer join (select count(*) as tableB from tableB) b
       full outer join (select count(*) as tableC from tableC) c
       full outer join (select count(*) as tableD from tableD) d
任性一次 2024-11-12 17:58:17

试试这个:


其中
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;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文