-2

我有一个包含 4 列的数据库:

  1. 地点
  2. 日期
  3. 队名
  4. 分数

我需要结果页面来选择并组合“Team_Name”(当相等时)和“Score”总和,并且仅在单个位置“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);
?>
4

1 回答 1

0
SELECT  Team_Name, SUM(Score) totalScore
FROM    tableName
WHERE   Location = 'BW3Avon' AND
        MONTH(Date) = MONTH(CURDATE())
GROUP   BY Team_Name
于 2013-01-17T00:05:46.433 回答