本文介绍了从SQL SUM查询中排除某些字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过SQL使用以下SUM查询
I am using the following SUM query with SQL
SELECT SUM(cost) as total FROM sales where passport =
我如何从计算中排除某些记录,例如,其中薪金= 1?
How would I exclude certain records from the calculation, for example where paid = 1?
推荐答案
简单
SELECT SUM(cost) as total
FROM sales
WHERE passport = ?
AND paid <> 1
您可能还在这里寻找一个团体
You may also be looking for a group by here
SELECT passport, SUM(cost) as total
FROM sales
WHERE passport = ?
AND paid <> 1
GROUP BY passport
这篇关于从SQL SUM查询中排除某些字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!