列如:
select A,sum(B) as bb,C from TB group by A,bb,C
怎么样才能只根据第一个字段A 来分组 后面的 bb,c 不管是什么都不没关系。谢谢
10 个解决方案
#1
select A,sum(B) as bb from TB group by A
#2
select A,sum(B) as bb from TB group by A
#3
select A,sum(B) as bb from TB group by A
#4
select A,sum(B) as bb,C,D,E,F from TB group by A,bb,C
我SELECT 后面还有很多字段呢 怎么就只根据A来分组呢
我SELECT 后面还有很多字段呢 怎么就只根据A来分组呢
#5
select A,sum(B) as bb from TB group by A
还是要:
select A,B=(select sum(b) from TB where a=t.a),C from tb t group by a,c
#6
试试:
select *,B=(select sum(b) from TB where a=t.a) from tb t
#7
select A,sum(B) as bb,C,D,E,F from TB group by A,bb,C,D,E,F
如果后面把bb,c,d,e,f 去掉之后会提示 C,D,E,F 无效 因为不包含在聚合函数中
如果后面把bb,c,d,e,f 去掉之后会提示 C,D,E,F 无效 因为不包含在聚合函数中
#8
select *,B=(select sum(b) from TB where a=t.a) from tb t
这样 并没有根据 需要的A 来分组
select A,sum(B) as bb,C,D,E,F from TB group by A,bb,C,D,E,F
但是 E,F 是必须的
#9
select A,sum(B) as bb,max(C) C from TB group by A
#10
select *,B=(select sum(b) from TB where a=t.a) from tb t
#1
select A,sum(B) as bb from TB group by A
#2
select A,sum(B) as bb from TB group by A
#3
select A,sum(B) as bb from TB group by A
#4
select A,sum(B) as bb,C,D,E,F from TB group by A,bb,C
我SELECT 后面还有很多字段呢 怎么就只根据A来分组呢
我SELECT 后面还有很多字段呢 怎么就只根据A来分组呢
#5
select A,sum(B) as bb from TB group by A
还是要:
select A,B=(select sum(b) from TB where a=t.a),C from tb t group by a,c
#6
试试:
select *,B=(select sum(b) from TB where a=t.a) from tb t
#7
select A,sum(B) as bb,C,D,E,F from TB group by A,bb,C,D,E,F
如果后面把bb,c,d,e,f 去掉之后会提示 C,D,E,F 无效 因为不包含在聚合函数中
如果后面把bb,c,d,e,f 去掉之后会提示 C,D,E,F 无效 因为不包含在聚合函数中
#8
select *,B=(select sum(b) from TB where a=t.a) from tb t
这样 并没有根据 需要的A 来分组
select A,sum(B) as bb,C,D,E,F from TB group by A,bb,C,D,E,F
但是 E,F 是必须的
#9
select A,sum(B) as bb,max(C) C from TB group by A
#10
select *,B=(select sum(b) from TB where a=t.a) from tb t