我有一个包含4列的数据库:
我需要结果页面选择并组合“Team_Name”WHEN等于和SUM“得分”AS总计,并且仅在单个位置“BW3Avon”显示当前月份。
这是我的代码
<?php
$con = mysql_connect("localhost","*******_admin","g********1");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("x0kqgoub_bw3avonscore", $con);
$sql = "SELECT * FROM bw3avonscore WHERE MONTH(myDate) = MONTH(CURRENT_DATE)";
$result = mysql_query("SELECT * FROM bw3avonscore Team_Name ORDER BY Score DESC");
while($row = mysql_fetch_array($result))
{
echo $row['Team_Name'] . " " . $row['Score'];
echo "<br />";
}
mysql_close($con);
?>
答案 0 :(得分:0)
SELECT Team_Name, SUM(Score) totalScore
FROM tableName
WHERE Location = 'BW3Avon' AND
MONTH(Date) = MONTH(CURDATE())
GROUP BY Team_Name