gpt4 book ai didi

mysql 从两个单独的查询中创建选择结果

转载 作者:行者123 更新时间:2023-11-29 13:26:47 24 4
gpt4 key购买 nike

我正在尝试创建一个 SQL 查询,该查询创建一个联赛表,其中包含标题球队名称、参加的比赛、总得分和每场比赛的平均得分。

所玩游戏的查询是:选择团队名称,COUNT(*) AS 玩过的游戏来自赛程GROUP BY team_name;

查询总得分为:选择团队team_name,COUNT( * ) AS 获得的总点数来自分数球员球队WHERE 分数.player_id=玩家.player_idAND 玩家.team_name = teams.team_name团队分组。team_name

如何组合两个查询以获取一个结果中的所有数据?

最佳答案

这应该有效:

SELECT teams.team_name, COUNT(*) AS total_points_gained,
(SELECT COUNT(*) FROM fixtures WHERE fixtures.team_name = teams.team_name) AS games_played
FROM scores,players,teams
WHERE scores.player_id=players.player_id
AND players.team_name = teams.team_name
GROUP BY teams.team_name

关于mysql 从两个单独的查询中创建选择结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20020119/

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