[英]how would I alter this mysql query to include another mysql table?
之前我問過一個問題,該問題是根據足球結果列表動態創建表格的,我忘了添加,后來意識到是缺少某些東西,基本上我想在輸出表格中包括俱樂部徽章。
這是在瀏覽器中即時生成表的代碼
$sqlCommand = "
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, homebadge badge, goalsfor, goalsagainst from serie_a_2010_2011
union all
select awayteam, awaybadge, goalsagainst, goalsfor from serie_a_2010_2011) a
group by team
order by score desc, goal_diff desc";
我在數據庫中創建了另一個具有以下結構的表,稱為徽章
----------------------------------------------
| id | team | badge |
----------------------------------------------
| 1 | Inter | (link to image of Inter badge)|
----------------------------------------------
| 2 | Milan | (link to image of Milan badge)|
----------------------------------------------
etc etc
這包括將在排行榜中輸出的所有球隊
我將如何創建/添加/加入/額外查詢,以為合適的團隊輸出合適的徽章?
我會說在所選字段列表中添加badges_table.badge
(選擇后立即添加)
然后在GROUP之前添加LEFT JOIN badges_table ON badges_table.id = tableThatHasBadge.badgeField
,這應該可以幫助您:)
讓我知道你是否還有顧慮
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.