第二周总结
题目总结
day06
6.1
1.(使用工具或者sq|命令)完成Vspace项目中所有表的创建
6.2
1.根据Vspace项目E-R图的关系将上一章创建好的表之间的外键关联关系建立起来
6.3
- 在商品分类表中新增两种类型
commit rollback
update 等等 - 在商品表中插入两个新的商品数据,新商品的类型属于第1步中新增的类型
insert into VSPACE.I_USER(good_id,good_title,price,discount,
specifiption,description,category_id,
ammount,image_url,up_date,down_date) values(1021,咸鸭蛋,25.8,1.0,1Kg/份,五芳斋,10只装咸鸭蛋礼盒,中华老字号,多油出油咸蛋,送礼特产礼品600g,27,url,999900:00:00);
insert into VSPACE.I_USER(good_id,good_title,price,discount,
specifiption,description,category_id,
ammount,image_url,up_date,down_date) values(1036,哈尔滨啤酒,67.9,1.0,1个/份,罗技鼠标,40,9999,imag,2019-12-15 00:00:00,9999-12-15 00:00:00);
6.4
1.使用两种方式实现Vspace项目数据的导入
使用disql
使用dts
day07
7.1
1 查询价格在50.0到100.0元之间的商品信息
select * from i_goods where price>=50 and price<=100;
2 查询商品标题中包含"肉"的商品信息
select * from i_goods where
goods_title like '%肉%';
3 查询购买订单数量超过11个的用户手机号码
select phone from i_order where ammount>11;
4 请使用top,limit和伪列三种方式实现商品信息的分页查询,要求每页显示3条数据,显示第5页的数据
select *from i_goods limit 12,3;
select top 15 *from i_goods;
select top 3 *from i_goods where goods_id not in (
select top 12 goods_id from i_goods
);
select rowid,*from i_goods where rowid between 13 and 15;
7.2
1从商品信息列表中查询包含“五花肉”的商品标题信息,并从标题中截取出“五花肉”这个字符串
select *from i_goods where goods_title like '%五花肉%';
select substring('猪五花肉',2,3);
2 请使用随机数函数得到任意一个随机三位数
select floor(rand()*(999-100+1)+100);
3查询最近10天的订单信息
select* from i_order where datediff (DD,order_date,curdate)<=10;
4 查询统计最近一个月的总销售额
select sum(sum_proce) from i_order where datediff (DD,order_date,curdate)<30;
7.3
1使用多表内联接(两种方式)查询用户手机号码、密码、注册时间、昵称信息
select u.phone,u.password,b.nick_name,b.reg_date,b.phone,
u.phone,b.phone
from i_user u inner join i_basic b
on u.phone=b.phone;
select u.phone,u.password,b.nick_name,b.reg_date,b.phone,
u.phone,b.phone
from i_user u,i_basic b
where u.phone=b.phone;
2查询用户手机号、昵称、下单时间、订单商品标题、商品数量、总价等信息
--查询用户手机号、昵称、下单时间、订单商品标题、商品数量、总价等信息
select b.phone,b.nick_name,g.goods_title,g.ammount,g.price
from i_basic b,i_cart c,i_goods g
where b.phone=c.phone and g.goods_id=c.goods_id
3.查询显示所有类型的商品,如果某个类型没有对应的商品则显示为空
--3.查询显示所有类型的商品,如果某个类型没有对应的商品则显示为空
select *from i_goods g
left outer join i_category ca
on g.category_id=ca.category_id
7.4
1.请用子查询查找年龄最小的用户的基本信息
--1.请用子查询查找年龄最小的用户的基本信息
select *from i_basic where birthday in(
select max(birthday) from i_basic
);
2.请用子查询查找所有商品以及该商品所属的一级类型名称
--2.请用子查询查找所有 商品以及该商品所属的一级类型名称
select goods_id,goods_title,(
select category_name from i_category where
category_id=(
select parent_id from i_category
where category_id=g.category_id
)
) 一级类型名称 from i_goods g;
3.分页查询订单编号、用户身份证号、商品名称、商品数据量、总价,要求每页显示7条,显示第5页的数据
--3.分页查询订单编号、用户身份证号、商品名称、商品数据量、总价,要求每页显示7条,显示第5页的数据
select o.order_id,b.id_card,(
select goods_title from i_goods where goods_id=o.goods_id),
o.ammount,o.sum_price from i_order o,i_basic b
where o.phone=b.phone limit 28,7;
day08
8.1_2
1.查询球队赛程信息表:比赛时间 主队名称 客队名称 比赛结果
-- 方法一: 使用多表联查查询所有的赛程信息
-- 要求包括: 比赛日期,主队名称,客队名称,主队得分,客队得分
select s.GAME_DATE, h.TEAM_NAME,g.TEAM_NAME,
s.HOST_SCORE,s.GUEST_SCORE from g_schedule s,g_team h,
g_team g where s.HOST_TEAM=h.TEAM_ID and s.GUEST_TEAM=g.TEAM_ID;
-- 方法二: 使用子查询实现以上的功能
select game_date,(
select team_name from g_team where team_id=host_team
) 主队,(
select team_name from g_team where team_id=guest_team
)客队,
host_score,guest_score
from VSPACE.G_SCHEDULE;
2.查询所有的好友关系, 要求显示主人昵称,好友昵称,好友关系
-- 查询好友关系: 要求显示我的昵称 , 好友昵称 ,关系
select * from q_friendship;
select * from q_user;
-- 使用多表联查的方式
select m.NICK_NAME,f.NICK_NAME,s.SHIP
from q_friendship s,q_user m,q_user f
where s.MY_QQ=m.QQ and s.FRIEND=f.qq;
-- 使用子查询的方式
select (
select nick_name from q_user where qq=s.my_qq
)我的昵称,(
select nick_name from q_user where qq=s.friend
) 好友昵称,s.ship from q_friendship s;
3.查询同时添加了A用户和B用户为好友的用户信息
-- 查询同时添加了3333和4444为好友的用户信息
-- ①: 先查询出添加了3333为好友的用户信息
select my_qq from Q_FRIENDSHIP where friend=3333;
-- ②: 在①的基础上筛选出添加4444为好友的用户信息
select my_qq from Q_FRIENDSHIP where friend=4444
and my_qq in(
select my_qq from Q_FRIENDSHIP where friend=3333
);
-- 方法二
select a.MY_QQ from (
select my_qq from Q_FRIENDSHIP where friend=3333
)a,(
select my_qq from Q_FRIENDSHIP where friend=4444
)b where a.my_qq=b.my_qq;
4.查询好友最多用户信息
-- 查询好友最多的用户信息
select my_qq,count(id) num from Q_FRIENDSHIP
where ship=1 group by my_qq;
-- 将上一步查询的结果看做虚拟表统计的最大好友数量值
select max(num) max_num from (
select my_qq,count(id) num from Q_FRIENDSHIP
where ship=1 group by my_qq
) t;
-- 根据上一步查询的最大值去筛选分组得到好友最多的用户qq
select my_qq,count(id) num from Q_FRIENDSHIP
where ship=1 group by my_qq having count(id)=(
select max(num) max_num from (
select my_qq,count(id) num from Q_FRIENDSHIP
where ship=1 group by my_qq
) t
);
8.3_4
1.查询子类型最多的一级商品类型
-- 1.查询子类型最多的一级商品类型
select * from i_category;
-- ①: 先排除父类型编号为0再按照父类型编号进行分组统计每种父类型下的子类型
select parent_id,count(category_id) sln from i_category
where parent_id !=0 group by parent_id;
-- 分析思路一: 将上一步查询的结果按照统计数量降序排列取第一个
select parent_id from i_category
where parent_id !=0 group by parent_id order by
count(category_id) desc limit 0,2;
------------------------------------------------------------
-- 将上一步查询得到类型编号作为条件去查询该一级类型的详细信息
select * from i_category where category_id=(
select parent_id from i_category
where parent_id !=0 group by parent_id order by
count(category_id) desc limit 0,1
);
2.查询显示每个月份销量最好的商品信息
-- 2.查询显示每个月份销量最好的商品信息
-- 明确: 查询统计订单信息
-- 查询统计出: 每个月每种商品的销量
-- ①: 按照月份和商品编号分组统计每个月每种商品的销量
select month(order_date) mon,goods_id,sum(ammount) sales
from i_order group by month(order_date),goods_id;
-- ②: 将①查询的结果看做虚拟表再次按照月份分组得到每个月最大的销量值
select mon, max(sales) max_salse from (
select month(order_date) mon,goods_id,sum(ammount) sales
from i_order group by month(order_date),goods_id
) t group by mon;
-- 将①和②的查询结果看做两张虚拟表进行多表联查
select a.* from (
select month(order_date) mon,goods_id,sum(ammount) sales
from i_order group by month(order_date),goods_id
)a,(
select mon, max(sales) max_salse from (
select month(order_date) mon,goods_id,sum(ammount) sales
from i_order group by month(order_date),goods_id
) t group by mon
)b where a.MON=b.MON and a.sales=b.MAX_SALSE order by mon;
3.将销售订单量最少的商品下架(下架是指: 将商品下架日期设置为当前系统日期)
--3.将销售订单量最少的商品下架(下架是指: 将商品下架日期设置为当前系统日期)
-- 假设: 忽略一个都没有卖出去的商品的情况
-- ①: 查询订单表,按照商品编号进行分组,统计每种商品交易订单数量
select goods_id,count(order_id) orderNum
from i_order group by goods_id;
-- ②: 在第①步的基础上将①查询结果看做虚拟表进行子查询统计出最小订单数量值
select min(orderNum) from (
select goods_id,count(order_id) orderNum
from i_order group by goods_id
) t;
-- ③: 在第①和②步的基础上筛选分组得到交易订单总数最小的商品编号
select goods_id from i_order group by goods_id
having count(order_id)=(
select min(orderNum) from (
select goods_id,count(order_id) orderNum
from i_order group by goods_id
) t
);
-- ④: 根据第③步得到的符合条件商品编号去修商品表,将下架日期该程当前系统日期
update i_goods set down_date=curdate() where goods_id in(
select goods_id from i_order group by goods_id
having count(order_id)=(
select min(orderNum) from (
select goods_id,count(order_id) orderNum
from i_order group by goods_id
) t
)
);
commit;
4.查询用户15112345678购买数量最多的商品的一级类型
-- 4.查询用户15112345678购买数量最多的商品的一级类型
-- 先查看订单数据情况再进行分析
select * from i_order;
-- ①: 去订单表中筛选出15112345678这个用户的所有购买记录
select * from i_order where phone='15112345678';
-- ②: 在第①步的基础上按照商品编号分组,统计每种商品购买总数量
select goods_id,sum(ammount)sumNum from i_order
where phone='15112345678' group by goods_id;
-- ③: 在第②步的基础上按照购买数量降序排列取第1个
select goods_id from i_order
where phone='15112345678' group by goods_id order
by sum(ammount) desc limit 0,1;
-- ④: 根据第③步查询到的商品编号去商品表中查询该商品的二级类型编号
select category_id from i_goods where goods_id=(
select goods_id from i_order
where phone='15112345678' group by goods_id order
by sum(ammount) desc limit 0,1
);
-- ⑤: 根据第④步查询到的二级类型编号去类型表中查询该类型的父类型编号
select c.parent_id,(
select category_name from i_category where category_id=c.parent_id
)一级类型名称
from i_category c where category_id=7;
-- 或者
-- 根据二级类型编号查询该类型的父类型编号
select parent_id from i_category where category_id=7
-- 根据父类型编号去查询一级类型详细信息
select * from i_category where category_id=(
select parent_id from i_category where category_id=(
select category_id from i_goods where goods_id=(
select goods_id from i_order
where phone='15112345678' group by goods_id order
by sum(ammount) desc limit 0,1
)
)
);
5.根据第4步的查询结果给15112345678这个用户推送他喜欢购买的类型的商品中销量最好两种商品给他
day09
9.1
1.创建视图用于查询最近10条订单信息,要求显示订单编号、商品标题、商品单价、商品数量、订单日期、订单总价
2.使用第1步创建的视图进行查询,查询成功后删除视图
3.创建一个测试表,添加百万测试数据,对比有没有索引情况下相同查询的时间消耗
9.2
14. 完成数据库全库脱机备份
15. 删除DMHR表空间
16. 还原数据库,观察删除内容是否正常恢复
9.3
1.使用DM管理工具完成联机全库备份
2.通过第1步的备份集文件还原数据库
3.使用DM管理工具完成联机增量备份
4.通过第3步中增量备份集还原数据库
9.4
17. 使用console工具完成脱机增量备份还原操作
18. 使用DMRMAN工具完成脱机增量备份还原操作
3.使用DM管理工具实现联机增量备份操作
day10
10.1
1.使用DM管理工具实现逻辑导入、导出(用户级别、模式级别)
2.使用命令实现逻辑导入、导出(用户级别、模式级别)
10.2
1.创建两个作业分别是job1和job2,job1负责每周日、周三完事23:00做全库备份,job2负责每周一、二、四、五、六晚上00:00做增量备份
2.完成达梦数据库0DBC插件安装配置并使用isql命令连接成功
3.测试jdbc连接达梦数据库