2015-09-05 110 views
0

我正在嘗試使用以下查詢從表中的多列。mysql SUM列

$res1 = $db->prepare('SELECT sum(kill) as kill, 
    SUM(death) as death, SUM(assist)as assit FROM eventgame GROUP BY player'); 
$res1->execute(); 
while ($row = $res1->fetch(PDO::FETCH_ASSOC)) { 
echo '.$row['player'] .$row['kill'] .$row['death'] .$row['assit'].';} 

什麼,我試圖做的是從每個球員得到總,如:

PLAYER |殺死|死亡| assit

player1 | 10 | 5 | 26

player2 | 5 | 10 | 35

我一直在嘗試這個過去2天左右,纔來到這裏尋求幫助。

我正在使用PDO連接到我的數據庫。

回答

3

您確實沒有準備帶有綁定參數的語句,就像您正在運行查詢一樣。從事物的mysql的邊,嘗試像

SELECT player, sum(kill) as kill, SUM(death) as death, SUM(assist) as assist 
FROM eventgame 
GROUP BY player 
order by player 

您GROUP BY不在聚合函數(如求和平均計數最小值最大值等)

+0

I'v嘗試,但我的一列或多列無法讓它工作。 GG –