我有一个表(查询和PHP)这样的体育排名页面: 我在表中有4个团队:
当pionts相等并且team4更好时,如何逐点排序 因为它是2场比赛team3 vs team4的胜利者?
------------------------------------------
--Data setup
------------------------------------------
CREATE TABLE Teams (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL,
rank INT(10),
win INT(10) NOT NULL,
loss INT(10) NOT NULL,
tie INT(10) NOT NULL,
dgoals INT(10) NOT NULL
)
CREATE TABLE Matchs (
mid INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
home VARCHAR(30) NOT NULL,
away VARCHAR(30) NOT NULL,
homescore INT(10) NOT NULL,
awayscore INT(10) NOT NULL
)
INSERT INTO Matchs (home, away, homescore, awayscore)
VALUES
('Team1','Team2',2,1),('Team2','Team1',1,1),
('Team3','Team4',3,2),('Team4','Team3',5,1),
('Team1','Team3',1,1),('Team3','Team1',1,1),
('Team2','Team4',1,1),('Team4','Team2',1,1),
('Team1','Team4',1,1),('Team4','Team1',1,1),
('Team2','Team3',1,1),('Team3','Team2',1,1)
INSERT INTO Teams (name, win, loss, tie, point, dgoals)
VALUES
('Team1',1,0,5,8,1),
('Team2',0,1,5,5,-1),
('Team3',1,1,4,7,-3),
('Team4',1,1,4,7,3)
------------------------------------------
--Answer
------------------------------------------
$result = $db->query("SELECT id,name, point FROM Teams ORDER BY point DESC");
$rank=1;
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$rank."</td><td>".$row["name"]." ".$row["point"]."</td></tr>";
$rank++;
}
------------------------------------------
--Question
------------------------------------------
how sort teams by point when pionts is equal AND team4 is better ,
because it is winner of 2 matchs team3 vs team4 ?
例如: 我想逐点点,但team2和team3有相同的分数 对于这个例子,team2是与team3的总和(匹配)的赢家,所以team2有排名,输出是排名,如何得到排名?
Team rank W L T point goals
—————————————————————————————————————
Team2 ? 6 2 2 20 +8
Team3 ? 6 2 2 20 +8
matchs home away score_h score_a
—————————————————————————————————————————
match1 team2 team3 2 1
match2 team3 team2 1 1