学习大数据DAY49 考后练习题

前几天在考帆软,考完后还有周末大礼包。

Oracle 上机练习

--第一题
create table 客户交易情况
(
客户号 varchar2(5),
交易时间 varchar2(20),交易金额 number(5)
);
--表中内容手动录入
select dense_rank()over(order by ascii(客户号)) as 序号 1,客户号,
dense_rank()over(order by to_date(交易时间,'yyyymmdd')) as 序号 2,交易时间,交
易金额
from 客户交易情况 order by ascii(客户号);

--第二题
create table 客户资料 1
(
客户号 varchar2(3),
客户名 varchar2(5),
年龄 number(5));
create table 客户资料 2
(
客户号 varchar2(3),
客户名 varchar2(5),
年龄 number(5)
);
--表中数据手动插入的
--第二题第一小题
select * from 客户资料 1
union
select * from 客户资料 2
--第二题第二小题
select 客户资料 1.*,
case when 客户号 not in
(
select 客户号 from 客户资料 2
) then '否'
else '是'
end as 是否在表二
from 客户资料 1
--第三题第三小题
select 客户资料 1.客户号 as 客户号 1,客户资料 1.客户名 as 客户名 1,客户资料
1.年龄 as 年龄 1,
客户资料 2.客户号 as 客户号 2,客户资料 2.客户名 as 客户名 2,客户资料 2.年龄
as 年龄 2
from 客户资料 1 full join 客户资料 2 on 客户资料 1.客户号=客户资料 2.客户号

--第四题

create table 品质解析
(
CD varchar2(3),
CD_DESC varchar2(5)
);
create table 客户与品质等级
(
客户号 varchar2(3),
CD varchar2(3)
);
--数据内容手动插入
--方法一
select 客户号,CD_DESC
from 客户与品质等级
left join 品质解析
on 客户与品质等级.CD=品质解析.CD
order by ascii(客户号)
--方法二select 客户号,
case CD when '1' then '普通'
when '2' then '潜力'
when '3' then '优质'
when '4' then '财富'
when '5' then '私行'
end as CD_DESC
from 客户与品质等级
order by ascii(客户号)

--第五题

create table List 订单
(
客户 varchar2(3),
购买产品 varchar2(8),
购买时间 varchar2(10)
);
--数据内容手动插入
select 客户,listagg(购买产品,',')within group(order by to_date(购买时
间,'yyyymmdd')) as 购买产品 from List 订单
group by 客户;

--第六题

create table 客户交易时间
(
客户 varchar2(3),
交易日期 varchar2(10)
);
select b.最后交易月份最早日期,a.客户,a.是否连续交易三个月
from
(
select 交易日期,客户,
case when months_between(to_date(交易日期,'yyyymmdd'),
lag(to_date(交易日期,'yyyymmdd'),2)over(partition by 客户 order by 交易日
期))=2 then '是'
else '否'
end as 是否连续交易三个月
from 客户交易时间
) a right join
(
select 客户,to_char(min(to_date(交易日期,'yyyymmdd')),'yyyymmdd') as 最后
交易月份最早日期
from 客户交易时间
where to_char(to_date(交易日期,'yyyymmdd'),'yyyymm')='202103'
group by 客户
) b on a.交易日期=b.最后交易月份最早日期 and a.客户=b.客户--第八题
create table 同环比
(
年月 varchar2(10),
数据 number(15,6)
);
select * from 同环比
--数据手动导入
select 年月,
case 上个月数据 when 0 then '无'
else round(数据/上个月数据*100,2)||'%'
end as 同比,
case 去年同月数据 when 0 then '无'
else round(数据/去年同月数据*100,2)||'%'
end as 环比
from
(
select a.年月,a.数据,nvl(b.数据,0) as 上个月数据,nvl(c.数据,0) as 去年同月数据
from 同环比 a
left join 同环比 b on to_date(a.年月,'yyyymm')=add_months(to_date(b.年月,'yyyymm'),1)
left join 同环比 c on to_date(a.年月,'yyyymm')=add_months(to_date(c.年
月,'yyyymm'),12)
)

--第八题
create table 同环比
(
年月 varchar2(10),
数据 number(15,6)
);
select * from 同环比
--数据手动导入
select 年月,
case 上个月数据 when 0 then '无'
else round(数据/上个月数据*100,2)||'%'
end as 同比,
case 去年同月数据 when 0 then '无'
else round(数据/去年同月数据*100,2)||'%'
end as 环比
from
(
select a.年月,a.数据,nvl(b.数据,0) as 上个月数据,nvl(c.数据,0) as 去年同月数据
from 同环比 a
left join 同环比 b on to_date(a.年月,'yyyymm')=add_months(to_date(b.年月,'yyyymm'),1)
left join 同环比 c on to_date(a.年月,'yyyymm')=add_months(to_date(c.年
月,'yyyymm'),12)
)

你问我第七题去哪了?我不会写。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值