sql语句如何把查询结果中某一字段相同的列的另一字段值相加 应该怎么写

如题所述

假设表table有字段a,b,c,现在要把a相同的,b相加,假设b是int类型,语句:
select
sum(b)
from
table
where
a
in
(
select
a
from
table
group
by
a
having
count(a)
>
1
)
and
sum(b)
<
某个值
group
by
a
不显示的在语句再加判断条件就好了
温馨提示:内容为网友见解,仅供参考
第1个回答  2019-10-09
你的意思是表tb中有 b,c两列?然后查询tb,若b中的值相同,则把相同的b值,对应的c字段的值加起来?!
select b,sum(c) from tb group by b若要在过滤
sum(c)<=某值的,
select b,sum(c) from tb group by b having sum(c)<=某值
相似回答