SQL 关于一次打印 3 个表的查询

SQL query about printing 3 tables at once

代码:

 select count(*) AS "NR_COMEDIES" from COMEDY

 select count(*) AS "NR_DRAMAS" from DRAMA 

 select count(*) AS "NR_TRAGEDIES" from TRAGEDY

我正在尝试将所有 3 个 table 的计数函数打印为一个大 table。

其中每个 table 都有自己的列,从上面命名。我怎样才能在一个巨大的 table 中制作所有 3 个 table?

我尝试使用 union,但它不起作用。

可能 CROSS JOIN 适合你

SELECT A.NR_COMEDIES,
       B.NR_DRAMAS,
       C.NR_TRAGEDIES
FROM   (SELECT Count(*) AS "NR_COMEDIES"
        FROM   COMEDY) A
       CROSS JOIN (SELECT Count(*) AS "NR_DRAMAS"
                   FROM   DRAMA)B
       CROSS JOIN (SELECT Count(*) AS "NR_TRAGEDIES"
                   FROM   TRAGEDY) C 

或在所有查询之间执行 Cartesian product

SELECT A.NR_COMEDIES,
       B.NR_DRAMAS,
       C.NR_TRAGEDIES
FROM   (SELECT Count(*) AS "NR_COMEDIES"
        FROM   COMEDY) A,
       (SELECT Count(*) AS "NR_DRAMAS"
        FROM   DRAMA)B,
       (SELECT Count(*) AS "NR_TRAGEDIES"
        FROM   TRAGEDY) C 

3 子选择...

select
    (select count(*) from COMEDY) as "NR_COMEDIES",

    (select count(*) from DRAMA) AS "NR_DRAMAS",

    (select count(*) from TRAGEDY) AS "NR_TRAGEDIES"
from
    SYSIBM.SYSDUMMY1