我有下表
AffID l Commision
-------------------------
MW001 5
MW004 10
MW001 25
MW001 5
MW004 5
我想提交一个计算列中金额的查询。例如,我正在寻找的输出是:
MW001 - 35
我现在使用的查询无法正常工作,它会计算实际的记录数量。
$sql = "SELECT COUNT(*) as c FROM toutcome WHERE affID = '" . $_SESSION['affID'] . "'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo $row['c'] ;
答案 0 :(得分:1)
尝试此查询
select sum(Commission) from toutcome where affID = 'MW001'
所以你的查询应该是
$sql = "SELECT SUM(Commission) as c FROM toutcome WHERE affID = '" . $_SESSION['affID'] . "'";
答案 1 :(得分:0)
查看所有可以汇总和分组的佣金
SELECT SUM(commission) FROM toutcome GROUP BY affID
所以看一个特定的人就这样做
SELECT SUM(commission) FROM toutcome WHERE affID = whicheveroneyouwant