编程题 银行三张表的

select * from o_trace_log;–业务流水
select * from o_mdm_ac_rel;–账号与客户介质表 卡和账户的
select * from o_dd_mst;–活期存款主文件
一个账户存在多个账号,一个客户存在一个账户信息
ac_type 客户类型 1-4为对公客户,5-6为个人账户;
流水表中存放的数据信息为当日的交易流水;

/*1、交易流水

找出账户为101214673(ac_id)的
卡号
交易
用子查询的方式*/
select * from o_trace_log
where ac_no in
(select ac_no from o_mdm_ac_rel
where ac_id=’101214673’);
select * from o_trace_log where ac_id=’101214673’;
——————删除重复数据:
delete from o_trace_log t2
where t2.rowid<
(select max(rowid) from o_trace_log t1
where t1.trace_no=t2.trace_no
and t1.trace_cnt=t2.trace_cnt
and t1.tx_date=t2.tx_date
group by t1.trace_no,t1.trace_cnt,t1.tx_date)

/*2、在活期账户主文件中找出徐耀华的账户用exists
实现*/
select * from o_dd_mst d where exists(
select 1 from o_mdm_ac_rel m where m.name =’徐耀华’
and d.ac_id=m.ac_id);

–in
select * from o_dd_mst d where d.ac_id in (
select ac_id from o_mdm_ac_rel m where
name=’徐耀华’ );

/*3、当天没有进行交易,且账户余额超过1000元的账户
有多少人?用not exists实现 表连接(左外连接)实现*/
select count(*) from o_dd_mst A where
not exists( —-账户不在交易流水表的记录内容
select ac_id from o_trace_log B
where A.ac_id=B.ac_id
) and bal>1000;

–表连接(左外连接)
select count(A.ac_id||A.ac_Seqn) from o_dd_mst A —count(*)也可以
left join
o_trace_log B
on A.ac_id=B.ac_id
where A.bal>1000
and B.ac_id is null —B表的任意一个为空

/*
select count(*) from o_dd_mst A where A.ac_id
not in(select ac_id from o_trace_log B ) and bal>1000;
*/

/*4、开户日期
最早的
第5人到第10人的数据,
去掉开户日期为0的垃圾数据*/ 第二表 d.opn_date <>0
select b.* from (
select d.* ,rownum rw from
(select * from o_dd_mst d where length(opn_date)=8 order by d.opn_date) d)b
where b.rw between 5 and 10;

select * from
(select round(rownum/2) rn,s.* from
(select * from o_dd_mst d where length(opn_date)=8
order by d.opn_date) s) where rn between 3 and 5;
————分页
select * from (
select ceil(rownum/15) page,t2.* from (
select * from o_dd_mst t1 where t1.opn_date<>0 order by t1.opn_date )t2 )
where page=2
/5、找出交易流水中名字长度大于4位的数据/
select * from o_trace_log where length(name)>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值