gpt4 book ai didi

php - 如何从 mysql 足球 [足球] 结果表中即时输出排名表?

转载 作者:IT老高 更新时间:2023-10-29 00:11:10 25 4
gpt4 key购买 nike

我一直在尝试查找有关此主题的内容,但似乎找不到任何内容,这里有一些问题,但它们不适用于我的特定项目。

我问了一个关于更新表格的类似问题,但它对我真正想要的不起作用 这是结果列表。

 --------------------------------------------------------
|id | hometeam |goalsfor|goalsagainst| awayteam |
--------------------------------------------------------
| 1 |Inter Milan | 3 | 1 | FC Barcelona |
--------------------------------------------------------
| 2 |FC Barcelona | 1 | 0 | Inter Milan |
--------------------------------------------------------
| 3 |Inter Milan | 4 | 0 | AC Milan |
--------------------------------------------------------
| 4 |AC Milan | 0 | 2 | Inter Milan |
--------------------------------------------------------
| 5 |Real Madrid | 2 | 0 | AC Milan |
--------------------------------------------------------
| 6 |AC Milan | 2 | 2 | Real Madrid |
--------------------------------------------------------
| 7 |FC Barcelona | 2 | 2 | AC Milan |
--------------------------------------------------------
| 8 |Real Madrid | 2 | 0 | Inter Milan |
--------------------------------------------------------
| 9 |Inter Milan | 3 | 1 | Real Madrid |
--------------------------------------------------------
| 10 |FC Barcelona | 2 | 0 | Real Madrid |
--------------------------------------------------------
| 11 |Real Madrid | 1 | 1 | FC Barcelona |
--------------------------------------------------------

基本上我希望能够创建一个按顺序对球队进行排名的排名表,我想即时显示这个表而不是将其放入数据库

Pos Team           Pld  W   D   L   F   A   GD  Pts
1 FC Barcelona 5 2 3 0 8 5 3 9
2 Inter Milan 6 2 2 2 11 10 1 8
3 Real Madrid 6 2 2 2 8 8 0 8
4 AC Milan 5 0 3 2 8 12 -4 3

POS=位置 W=赢 D=平 L=输 F=进球 A=进球 GD=进球差 Pts=积分

我认为最有效的方法是分配胜、平和负,将进球数和进球数相加,并在回显数据时计算总比赛场数和得分。

但是我如何分配输赢?并计算进球数和失球数?

最佳答案

首先将得分表合并在一起,交换主队和客队并交换进球数。这为您提供了一些易于聚合的源数据,生成记分卡的查询如下所示:

select 
team,
count(*) played,
count(case when goalsfor > goalsagainst then 1 end) wins,
count(case when goalsagainst> goalsfor then 1 end) lost,
count(case when goalsfor = goalsagainst then 1 end) draws,
sum(goalsfor) goalsfor,
sum(goalsagainst) goalsagainst,
sum(goalsfor) - sum(goalsagainst) goal_diff,
sum(
case when goalsfor > goalsagainst then 3 else 0 end
+ case when goalsfor = goalsagainst then 1 else 0 end
) score
from (
select hometeam team, goalsfor, goalsagainst from scores
union all
select awayteam, goalsagainst, goalsfor from scores
) a
group by team
order by score desc, goal_diff desc;

关于php - 如何从 mysql 足球 [足球] 结果表中即时输出排名表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8009379/

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