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 />";
}

DB 構造イメージ:

データベース構造

私が知りたいのは、小切手の合計と現在の金額のみを表示する方法です。

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 に答える