?!oracle中分组求各列的和并条件查询,这样的sql怎么写
朋友们帮帮忙..最好写出一个简单的例子,要求代码..就是:两表连接后做个统计并且分组的语句..大家帮忙....
朋友们帮帮忙..最好写出一个简单的例子,要求代码..
就是:两表连接后做个统计并且分组的语句.. 大家帮忙. 展开
就是:两表连接后做个统计并且分组的语句.. 大家帮忙. 展开
2个回答
展开全部
表名test
字段 type_id counts
1 2
1 3
2 2
2 8
select type_id,sum(counts) from test group by type_id;
结果
type_id counts
1 5
2 10
-------------补充-----------------
a表:
type_id name
1 服装
2 首饰
b表:
id type_id counts
1 1 4
2 2 5
3 1 8
4 2 2
select b.type_id,sum(counts) from a,b where a.type_id=b.type_id
group by b.type_id;
结果:
type_id counts
1 12
2 7
字段 type_id counts
1 2
1 3
2 2
2 8
select type_id,sum(counts) from test group by type_id;
结果
type_id counts
1 5
2 10
-------------补充-----------------
a表:
type_id name
1 服装
2 首饰
b表:
id type_id counts
1 1 4
2 2 5
3 1 8
4 2 2
select b.type_id,sum(counts) from a,b where a.type_id=b.type_id
group by b.type_id;
结果:
type_id counts
1 12
2 7
展开全部
select organization_id,declaration_id from YY_CUSTOM_DECLARATION_HEADER
结果:
organization_id declaration_id
88 157
88 156
88 158
select organization_id,sum(declaration_id) from YY_CUSTOM_DECLARATION_HEADER
group by organization_id
having sum(declaration_id)>0
结果:
organization_id sum(declaration_id)
88 471
select organization_id,sum(declaration_id) from YY_CUSTOM_DECLARATION_HEADER
group by organization_id
having sum(declaration_id)<0
结果:
无资料
结果:
organization_id declaration_id
88 157
88 156
88 158
select organization_id,sum(declaration_id) from YY_CUSTOM_DECLARATION_HEADER
group by organization_id
having sum(declaration_id)>0
结果:
organization_id sum(declaration_id)
88 471
select organization_id,sum(declaration_id) from YY_CUSTOM_DECLARATION_HEADER
group by organization_id
having sum(declaration_id)<0
结果:
无资料
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询