使用多个表创建表

发布于 2025-02-10 00:59:03 字数 750 浏览 5 评论 0原文

我正在尝试从多个表创建一个表。

表A包含ID列表,我需要在表C中存储的ID数。

表B具有ID列表,并且在表C中也需要它们的数量。

我正在尝试下面,但要遇到错误:

Create or replace tablec as 

select 
Count(id) as total
from table a,
select count(ref) as ref_total
from table b

我所需的输出应如下所示,应按日期进行过滤。

I'm trying to create a table from multiple tables.

table a has list of IDs and I need count of IDs stored in table C.
enter image description here

Table b has list of IDs and need the count of them as well in table C.
enter image description here

I'm trying below but getting an error:

Create or replace tablec as 

select 
Count(id) as total
from table a,
select count(ref) as ref_total
from table b

My desired output should look like below and should be filter applied by date.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

十六岁半 2025-02-17 00:59:03

考虑为每个计数使用一个子查询如下所示。

CREATE OR REPLACE TABLE TableC AS
SELECT (SELECT COUNT(id) FROM TableA) AS total,
       (SELECT COUNT(ref) FROM TableB) AS ref_total
;

输出:

”在此处输入图像描述“

但是日期范围是可选的。对于日期范围,我正在考虑将整个数据放在新表中,然后我可以在表C

上进行选择。

我认为您可以添加 date eftert 每个子查询的条款出于您的目的。

Consider using a subquery for each count like below.

CREATE OR REPLACE TABLE TableC AS
SELECT (SELECT COUNT(id) FROM TableA) AS total,
       (SELECT COUNT(ref) FROM TableB) AS ref_total
;

output:

enter image description here

But date range is something optional. For date range, I'm thinking to get whole data in new table then I can run select on table C

I think you can add date filter in WHERE clause of each subquery for your purpose.

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