| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1758 人关注过本帖, 1 人收藏
标题:请教2个问题
只看楼主 加入收藏
elvis123
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-11-24
收藏(1)
 问题点数:0 回复次数:4 
请教2个问题
[font=Arial]TABLE[/font]如下

日期
收入
支出

[font=Arial]2000/3/1 50 30[/font]
[font=Arial]2000/3/2 45 60[/font]
[font=Arial]2000/3/5 60 10[/font]
[font=Arial]2000/3/5 60 10 [/font]
能否用[font=Arial]SELECT[/font]語句得出以下結果

[font=Arial]1.[/font]
日期
收入
支出
餘額

[font=Arial]2000/3/1 50 30 20[/font]
[font=Arial]2000/3/2 45 60 5[/font]
[font=Arial]2000/3/5 120 20 105[/font]
[font=Arial]2.[/font]
日期
收入
支出
餘額

[font=Arial]2000/3/1 50 30 20[/font]
[font=Arial]2000/3/2 45 60 5[/font]
[font=Arial]2000/3/3 0 0 5[/font]
[font=Arial]2000/3/4 0 0 5 [/font]




[font=Arial][font=Arial][size=1][font=Arial][size=9pt]1.[/font][font=Arial]SQL Plus[/font]產生以下報表[font=Arial].(scott/tiger@mdstest)[/font]


[font=Arial]   1.[/font]使用表[font=Arial]emp,dept[/font]
[font=Arial]   2.[/font]寫成一個可以用在[font=Arial]SQL Plus[/font]中執行的[font=Arial]Script[/font]

使用[font=Arial]SQLPlus[/font][font=Arial]column[/font]等定義

[font=Arial]   3. Format[/font]



部門名稱
人數
工資總額



[font=Arial]        A                       2             1000[/font]
[font=Arial]        B                       3             2000[/font]
[font=Arial]        sum                                   3000[/font]
[font=Arial]最后一行SUM怎么加?[/font]
[/size][/font][/size][/font]
搜索更多相关主题的帖子: size 
2007-11-24 13:35
ILoveMK
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:487
专家分:0
注 册:2007-2-12
收藏
得分:0 
你的问题不难,我明天再给你答案吧,现在没空。

天下归心
2007-11-25 02:14
ILoveMK
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:487
专家分:0
注 册:2007-2-12
收藏
得分:0 
第一个问题:
SQL> select * from test;

COLA             COLB       COLC
---------- ---------- ----------
2000/03/01         50         30
2000/03/02         45         60
2000/03/05         60         10
2000/03/05         60         10

1.
select a,b,c,sum(d) over (order by a asc rows between unbounded preceding and current row) d from(
select cola a,sum(colb) b,sum(colc) c,sum(colb)-sum(colc) d from test
group by cola order by cola
) order by a
/

A                   B          C          D
---------- ---------- ---------- ----------
2000/03/01         50         30         20
2000/03/02         45         60          5
2000/03/05        120         20        105

2.
select a,b,c,sum(d) over (order by a rows between unbounded preceding and current row) d
from(
select cold a,nvl(sum(colb),0) b,nvl(sum(colc),0) c,nvl(sum(colb)-sum(colc),0) d
from test,
(select trunc(to_date('2000/03/01','yyyy/mm/dd'))+rownum-1 cold from dual
connect by rownum<(select to_number(to_char(max(cola),'dd'))+1 from test)) test2
where test2.cold=test.cola(+)
group by test2.cold
order by test2.cold
)
/

A                   B          C          D
---------- ---------- ---------- ----------
2000/03/01         50         30         20
2000/03/02         45         60          5
2000/03/03          0          0          5
2000/03/04          0          0          5
2000/03/05        120         20        105

第二个问题:
SQL> select * from test;

NAME         NUM        SAL
----- ---------- ----------
A              2       1000
B              3       2000

select nvl(name,'sum'),num,sum(sal) from test
group by rollup(name,num)
having grouping_id(name,num)!=1
/

NVL(N        NUM   SUM(SAL)
----- ---------- ----------
A              2       1000
B              3       2000
sum                    3000

天下归心
2007-11-25 21:05
飙马
Rank: 5Rank: 5
来 自:马里亚纳
等 级:贵宾
威 望:15
帖 子:779
专家分:280
注 册:2007-3-28
收藏
得分:0 
LS厉害!

IT精英如同彩票:平凡的人像5块也中不到一样普遍,努力一点你中了5元保了个本。奖金越高,机率也就越小,付出的也越多,盖茨如同500万一样稀有。虽然每天忙碌而平凡,但我努力成为精英,做梦中了500万。
2007-11-26 20:16
比蜗牛快些
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:124
专家分:0
注 册:2007-4-16
收藏
得分:0 
厉害" border="0" />
" border="0" />

地球人的缺点与恶习集一身,小心感染不良恶习
2007-12-04 21:59
快速回复:请教2个问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014242 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved