gpt4 book ai didi

mysql - 将两个具有不同架构的 SELECT 语句的结果 "generated"连接到一个表中

转载 作者:可可西里 更新时间:2023-11-01 06:34:51 25 4
gpt4 key购买 nike

所以我有以下 SELECT 语句:

SELECT COUNT(A.Award) AS US, SUBSTRING(CAST(M.Year as char(4)), 0 , 4)  AS Decade
FROM Movies M, Awards A
WHERE {SOME WHERE CLAUSE}
GROUP BY Decade;

SELECT COUNT(*) AS Total, SUBSTRING(CAST(A2.Year as char(4)), 0 , 4) AS Decade
FROM Awards A2
WHERE {SOME WHERE CLAUSE}
GROUP BY Decade;

第一个是“生成”一个包含列(US十年)的表,第二个是“生成”另一个包含列(总计)的表十年)。我想加入这两个表,以便得到一个表(USTotalDecade)。我该怎么做?

最佳答案

将它们放在子查询中并执行JOIN:

SELECT a.US, a.decade, b.total FROM

(SELECT COUNT(A.Award) AS US, SUBSTRING(CAST(M.Year as char(4)), 0 , 4) AS Decade
FROM Movies M, Awards A
WHERE {SOME WHERE CLAUSE}
GROUP BY Decade ) AS a

INNER JOIN

(SELECT COUNT(*) AS Total, SUBSTRING(CAST(A2.Year as char(4)), 0 , 4) AS Decade
FROM Awards A2
WHERE {SOME WHERE CLAUSE}
GROUP BY Decade) AS b

ON a.decade = b.decade

关于mysql - 将两个具有不同架构的 SELECT 语句的结果 "generated"连接到一个表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8106163/

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