将带有子查询的 mySQL 查询转换为带有子查询的 DB2 SQL 查询

Converting mySQL queries with subqueries to DB2 SQL query with subqueries

我对 DB2 SQL 服务器很陌生。我正在尝试从多个表中查询总行数,如下所示:

SELECT
 SUM(COUNT)
  AS ROWS
 FROM
 (SELECT COUNT(*) AS COUNT FROM TABLE1
 UNION ALL
SELECT COUNT(*) AS COUNT FROM TABLE2
 UNION ALL
SELECT COUNT(*) AS COUNT FROM TABLE3
 UNION ALL
//ETC...
)

但它一直在“)”上标记语法错误。我该如何重组它?

DB2(和 SQL 服务器)要求子查询使用别名,因此:

SELECT
 SUM(COUNT)
  AS ROWS
 FROM
 (SELECT COUNT(*) AS COUNT FROM TABLE1
 UNION ALL
SELECT COUNT(*) AS COUNT FROM TABLE2
 UNION ALL
SELECT COUNT(*) AS COUNT FROM TABLE3
 UNION ALL
//ETC...
) as subqueryAlias