银行三张表 作业:

本文介绍了SQL查询中处理数据的一些技巧,包括开户日期排序、行转列、筛选特定客户交易信息以及处理字符串重复字符的方法。同时展示了如何通过触发器确保数据库完整性。
摘要由CSDN通过智能技术生成

====================================
1.开户日期排序,去掉开户日期为0的垃圾数据,设置 sql中展示条数,和页数,展示要求的数据信息
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
第二种方式:
Select rownum as num ,t1.* from
(select * from o_dd_mst t where t.opn_date<>0 order by t.opn_date )t1 )t2 where t2.num >15*(6-1)and t2.num <=15*6

2.行转列
select max(t1.cif_no) 客户号,max(t2.name) 客户名称,
sum(decode(rownum,1,t1.ac_id,0)) 账户号1,
sum(decode(rownum,1,t1.bal,0)) 账户余额,
sum(decode(rownum,2,t1.ac_id,0)) 账户号2,
sum(decode(rownum,2,t1.bal,0)) 账户余额,
sum(decode(rownum,3,t1.ac_id,0)) 账户号3,
sum(decode(rownum,3,t1.bal,0)) 账户余额,
sum(decode(rownum,4,t1.ac_id,0)) 账户号4,
sum(decode(rownum,4,t1.bal,0)) 账户余额
from o_dd_mst t1
left join o_mdm_ac_rel t2
on t1.ac_id=t2.ac_id
and t1.ac_seqn=t2.ac_seqn
where cif_no = 10066744
group by t1.cif_no

方式二:子查询 多表关联 应该是第一种考虑方式
Select distinct t1.cif_no ,t2.name ,t3.ac_id,t3.bal
from o_dd_mst t1,o_mdm_ac_rel t2
(select ac_id,bal,cif_no from o_dd_mst t1 where cif_no = 10066744) t3,
(select ac_id,bal,cif_no from o_dd_mst t1 where cif_no = 10066744) t4,

where t1.ac_id=t2.ac_id
and cif_no = 10066744
and t3.cifno=t1.cifno
And t3.cifno<>t4.cifno
group by t1.cif_no

==========================

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值