请教 分组统计的 sql语句!!!

[复制链接]
查看11 | 回复4 | 2008-1-2 17:35:53 | 显示全部楼层 |阅读模式
drop table temptable cascade constraints;
/*==============================================================*/
/* Table: temptable
*/
/*==============================================================*/
create table temptable(
tempID
INTEGER,
tempNum
number
);

SQL> insert into temptable values(1,20);

1 row inserted

SQL> insert into temptable values(1,30);

1 row inserted

SQL> insert into temptable values(1,40);

1 row inserted

SQL> insert into temptable values(2,40);

1 row inserted

SQL> insert into temptable values(2,10);

1 row inserted

SQL> insert into temptable values(2,600);

1 row inserted

SQL> insert into temptable values(3,30);

1 row inserted

SQL> insert into temptable values(3,30);

1 row inserted

SQL> insert into temptable values(3,10);

1 row inserted

SQL> insert into temptable values(4,500);

1 row inserted
select * from temptable

TEMPIDTEMPNUM
--------------------------------------- ----------

1 20

1 30

1 40

2 40

2 10

2600

3 30

3 30

3 10

4500
请问 如何求出以下结果
1 求和
2 求和
3 求和
4 求和
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
select tempid,sum(tempnum) from temptable group by tempid; ???
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
谢谢了。
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
select tempid,sum(tempnum) from temptable group by tempid order by 1;
这是最基本的sum计算吧!
回复

使用道具 举报

千问 | 2008-1-2 17:35:53 | 显示全部楼层
哈哈!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行