gpt4 book ai didi

Php Mysql 对 2 列求和并从 2 个表中选择

转载 作者:行者123 更新时间:2023-11-29 09:32:56 25 4
gpt4 key购买 nike

我有一个包含 3 个表的 MySQL 数据库。

  • table 上玩家

P_id = content (1, 2, 3,)

P_name = content (Spieler1name, Spieler2name, Spieler3name)
  • table 上锦标赛

T_id = content (1, 2)

T_date = content (2018, 2019)

T_players = content (123, 123)
  • table 上游戏

G_id = content (1, 2)

G_tournament_id = content (T_id from table tournament)

G_player_away = Content (as an example user id 1)

G_player_home = content (as an example user id 2)

G_player_away_points = Content (11)

G_player_home_points = Content (8)

Games 表包含更多数据。

现在我想创建一个以 PhP 作为排名的表格。

地名点

  1. Spieler1name 11

  2. Spieler2name 8

  3. Spieler3name 4

  4. ....

有人可以告诉我 mysql 数据库的 php 查询是如何工作的吗?我测试了这个,但它不起作用。

SELECT SUM(G_player_away_points) AS total FROM Games 
UNION
SELECT SUM(G_player_home_points) AS total FROM Games
GROUP BY G_player_away

在上面的代码中,他还对对手的得分进行了求和。这当然是不正确的,应该只有他获得的分数才会出现在php表的输出中。此外,您还必须从牌 table 上的玩家那里获取姓名。有人可以帮助我吗?

最佳答案

如果您使用单表和多列求和,那么您应该尝试使用此方法

SELECT SUM(G_player_away_points + G_player_home_points) AS total FROM Games 
GROUP BY G_player_away

关于Php Mysql 对 2 列求和并从 2 个表中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58302783/

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