当前位置: 首页 > article >正文

学习大数据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)
)

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


http://www.kler.cn/news/290493.html

相关文章:

  • python学习8:dict字典的定义,操作和方法,跟json有什么区别?
  • 通过查找真实IP bypass WAF
  • 容器化你的应用:使用 Docker 入门指南
  • window 10使用wsl装docker踩坑
  • CCNA课笔记
  • 【NO.17】LeetCode经典150题-13. 罗马数字转整数
  • 装机必看!内存条应该怎么插?各种内存条插法详解
  • Seataf分布式事务的使用
  • 坐牢第三十四天(c++)
  • WordPress自适应美图网站整站打包源码
  • Docker镜像中的源替换为国内源
  • C/C++:函数指针
  • SpringBoot3集成Spring Authorization Server实现SSO单点登录
  • uniapp小程序实现横屏手写签名
  • 宠物智能家居监测器的融合
  • LeetCode 606.根据二叉树创建字符串
  • 开源vscode AI插件
  • 什么是基于云的 SIEM
  • MuseTalk模型构建指南
  • css改变鼠标样式
  • 论文速读|BiGym:一款基于演示的移动双手操作机器人基准
  • IO进程练习:请在linux 利用c语言编程实现两个线程按照顺序依次输出”ABABABAB......“
  • pdf转cad软件,5款快速上手转换软件分享
  • vue el-tree主键id重复 添加自增id 以及原相同节点同步勾选 同步操作
  • 在Ubuntu上使用apt工具安装RabbitMQ
  • 单链表的问题(2)
  • NCBI-get-GCFIDs_fast.py
  • 基于贝叶斯优化CNN-LSTM网络的数据分类识别算法matlab仿真
  • 戴尔科技领涨市场,AI服务器需求成关键驱动力
  • Error when attempting to add data source to Azure OpenAI api