假设表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
不显示的在语句再加判断条件就好了
你的意思是表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)<=某值