2012-05-03 46 views

回答

1

以下查詢:

SELECT 
    SUM(team1) AS team1_points, 
    SUM(team2) AS team2_points 
FROM 
    tbl_points 

會給你一個單行表作爲結果:

| team1_points | team2_points | 
| 60   | 35   | 

此外,使用名稱tbl_points不好。最好不要使用前綴。只要將你的名字命名爲points,這就足夠清楚了。

+0

這一個實際工作。感謝一羣人。 – Jetoox

+0

@jetoox,Riateche有一個很好的觀點:不要使用「tbl _」的前綴......從表格中顯而易見的查詢...還要注意列名不要使用可能是「保留字」的事物,如Date ,名稱,時間,計數,組等... – DRapp

+0

@DRapp使用tbl作爲前綴已經是我們編碼約定的一部分。你在肆意使用保留字是什麼?我甚至在上面使用它? – Jetoox

1

未經測試:

SELECT SUM(p1.team1) AS team1_score 
     , SUM(p2.team2) AS team2_score 
    FROM tbl_points AS p1 
     , tbl_points AS p2 
相關問題