0
$query = "SELECT agent_id, SUM(amount) FROM bill WHERE YEAR(date)  = YEAR(CURDATE()) AND MONTH(date) = MONTH(CURDATE()) GROUP BY agent_id"; 

$result = mysql_query($query) or die(mysql_error());

// Print out result
while($row = mysql_fetch_array($result)){
    echo "Total ". $row['agent_id']. " = $". $row['SUM(amount)'];
    echo "<br />";
}

数据库结构图像:

数据库结构

我想知道如何显示支票和金额的总和目前仅作为金额的总和

4

3 回答 3

0

试试这个(我从你的问题中理解) -

SELECT agent_id, (SUM(amount)+sum(cheque)) As total FROM bill WHERE YEAR(date)  = YEAR(CURDATE()) AND MONTH(date) = MONTH(CURDATE()) GROUP BY agent_id"; 
于 2013-01-07T14:28:23.370 回答
0

当然可以,您的查询将如下所示:

SELECT agent_id, SUM(amount + cheque) 
FROM bill 
WHERE YEAR(date) = YEAR(CURDATE()) 
AND MONTH(date) = MONTH(CURDATE()) 
GROUP BY agent_id
于 2013-01-07T14:28:35.273 回答
0
SELECT agent_id, (SUM(amount) + SUM(cheque)) AS total_amount
FROM bill WHERE YEAR(date)  = YEAR(CURDATE()) AND MONTH(date) = MONTH(CURDATE()) 
GROUP BY agent_id
于 2013-01-07T14:32:05.637 回答