解决了两个sql问题

Friday February 17, 2006 - 05:24pm (CST)

1。decode()不仅仅针对固定值

(case when (b.aggregateno is null or b.aggregateno='') then customerid else b.aggregateno end)
也可以写成
decode(aggregateno,null,customerid,'',customerid,aggregateno)
decode里面放的是字段,而不是固定值,case when的语法实在难以写正确。而sql又没有发现IDE,程序员离开IDE还有点难办,不过做IDE的人却不挣钱,Borland都要卖掉他们的IDE 部门了,不过今天公司竟然收到了Borland的邮件,说我们有人使用非正版的Jbuilder,唉....竟然还有人喜欢用Jbuilder,不是说他不好,而是他的商业版本也太没性价比了。

2。取前10条记录放入临时表的写法

本来这是一个简单问题,用select first 10 * from table1 into temp temptable 就解决了,但是into temp table或者insert into 的时候都不能使用first,Image。这种设计不知道出于什么考虑

/*先从所有记录中sum出总和,并且按中和排序放入临时表中,这样插入的记录rowid在非异常情况下是连续的,并且按sum值排序*/
select T1.aggregateno aggregateno, sum(T1.balance) sumbalance
from aggr_n T1
group by T1.aggregateno
order by 2 desc, 1 asc
into temp temptop1
/*取前10 的记录放入临时表,条件是rowid小于min(rowid)+10*/
select aggregateno,sumbalance from temptop1
where rowid < (select min(rowid)+10 from temptop1)
order by 2 desc into temp temptop10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值