gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 12:26:35 28 4
gpt4 key购买 nike

我对 DB2 SQL 服务器非常不熟悉。我正在尝试从多个表中查询总 rowCount,如下所示:

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 Server)要求子查询具有别名,因此:

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

关于mysql - 将带有子查询的 mySQL 查询转换为带有子查询的 DB2 SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28219623/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com