diff --git "a/06 \346\236\227\346\231\237\350\276\211/20230313\351\242\230\347\233\256.zip" "b/06 \346\236\227\346\231\237\350\276\211/20230313\351\242\230\347\233\256.zip" new file mode 100644 index 0000000000000000000000000000000000000000..2945d02fbd2314afebd6a2556a1164f722f7accf Binary files /dev/null and "b/06 \346\236\227\346\231\237\350\276\211/20230313\351\242\230\347\233\256.zip" differ diff --git "a/06 \346\236\227\346\231\237\350\276\211/20230315 \351\242\23036.md" "b/06 \346\236\227\346\231\237\350\276\211/20230315 \351\242\23036.md" new file mode 100644 index 0000000000000000000000000000000000000000..1b8637c494b2e6e385180d565f01bc5ac8c8502b --- /dev/null +++ "b/06 \346\236\227\346\231\237\350\276\211/20230315 \351\242\23036.md" @@ -0,0 +1,148 @@ +```MySQL +create database lol charset utf8; +use lol; +-- +-- +-- ### 1、相关表结构 +-- +-- 1. 英雄信息表 ( heroinfo ) +-- +-- | 字段名称 | 数据类型 | 说明及要求 | +-- | --------- | ----------- | :--------- | +-- | gameno | varchar(10) | 编号,主键 | +-- | edition | varchar(10) | 版本,非空 | +-- | name | varchar(10) | 姓名,非空 | +-- | fetter | varchar(50) | 羁绊,非空 | +-- | starlevel | int | 星级,非空 | +-- | cost | int | 费用,非空 | + +-- 2. 英雄属性信息表 ( attribute ) +-- +-- | 字段名称 | 数据类型 | 说明及要求 | +-- | -------- | ----------- | -------------------------- | +-- | gameno | varchar(10) | 编号,外键,关联英雄信息表 | +-- | hp | int | 血量,非空 | +-- | mp | int | 法力值,非空 | +-- | atk | int | 攻击力,非空 | +-- | ac | int | 护甲,非空 | + +-- ### 2、对应的表数据 +-- +-- 1. 英雄信息表 +-- +-- | 编号(NO) | 版本(edition) | 姓名(name) | 羁绊(fetter) | 星级(starlevel) | 费用(cost) | +-- | :--------: | :-----------: | :--------: | :----------------------: | :-------------: | :--------: | +-- | s1 | 未来战士 | 卢锡安 | 不定式,快枪手,混沌战士 | 2 | 6 | +-- | s2 | 未来战士 | 潘森 | 不定式,爱心使者 | 1 | 1 | +-- | s3 | 怪兽入侵 | 派克 | 裂隙行者,黑客 | 1 | 2 | +-- | s4 | 未来战士 | 慎 | 不定式,护卫,黑客 | 2 | 18 | +-- | s5 | 天选福星 | 纳尔 | 小天才,淘气包 | 3 | 27 | +-- | s6 | 怪兽入侵 | 莫甘娜 | 怪兽 | 2 | 18 | +-- | s7 | 怪兽入侵 | 薇古丝 | 裂隙行者,吉祥物 | 2 | 18 | +-- | s8 | 怪兽入侵 | 亚托克斯 | 怪兽 | 1 | 4 | +-- | s9 | 未来战士 | 崔斯特 | 不定式,决斗大师,灵能使 | 2 | 24 | +-- | s10 | 天选福星 | 妮蔻 | 星之守护者,灵能使 | 2 | 24 | +-- | s11 | 天选福星 | 盖伦 | 战斗机甲,护卫 | 3 | 36 | +-- | s12 | 怪兽入侵 | 烬 | 裂隙行者,混沌战士 | 2 | 24 | +-- | s13 | 未来战士 | 伊泽瑞尔 | 不定式,平行宇宙,枪手 | 3 | 45 | + +-- 2.英雄属性信息表 +-- +-- | 编号(NO) | 血量(hp) | 法力值(mp) | 攻击力(atk) | 护甲值(ac) | +-- | :------: | :--------: | :----------: | :-----------: | :----------: | +-- | s1 | 50 | 65 | 80 | 30 | +-- | s2 | 12 | 20 | 25 | 35 | +-- | s3 | 150 | 225 | 325 | 24 | +-- | s4 | 50 | 75 | 120 | 25 | +-- | s5 | 50 | 100 | 150 | 40 | +-- | s6 | 100 | 125 | 150 | 45 | +-- | s7 | 60 | 100 | 140 | 35 | +-- | s8 | 150 | 200 | 500 | 65 | +-- | s9 | 125 | 150 | 225 | 34 | +-- | s10 | 110 | 150 | 300 | 34 | +-- | s11 | 150 | 200 | 800 | 65 | +-- | s12 | 100 | 175 | 285 | 44 | +-- | s13 | 244 | 344 | 844 | 60 | + +-- 1.根据效果图创建表1,表2,并录入数据 +create table heroinfo( + gameno varchar(10), + edition varchar(10) not null, + name varchar(10) not null, + fetter varchar(50) not null, + starlevel int not null, + cost int not null +); + +create table attribute( + gameno varchar(10), + hp int not null, + mp int not null, + atk int not null, + ac int not null +); + +insert into heroinfo values + ('s1','未来战士','卢锡安','不定式,快枪手,混沌战士',2,6), + ('s2','未来战士','潘森','不定式,爱心使者',1,1), + ('s3','怪兽入侵','派克','裂隙行者,黑客',1,2), + ('s4','未来战士','慎','不定式,护卫,黑客',2,18), + ('s5','天选福星','纳尔','小天才,淘气包',3,27), + ('s6','怪兽入侵','莫甘娜','怪兽',2,18), + ('s7','怪兽入侵','薇古丝','裂隙行者,吉祥物',2,18), + ('s8','怪兽入侵','亚托克斯','怪兽',1,4), + ('s9','未来战士','崔斯特','不定式,决斗大师,灵能使',2,24), + ('s10','天选福星','妮蔻','星之守护者,灵能使',2,24), + ('s11','天选福星','盖伦','战斗机甲,护卫',3,36), + ('s12','怪兽入侵','烬','裂隙行者,混沌战士',2,24), + ('s13','未来战士','伊泽瑞尔','不定式,平行宇宙,枪手',3,45); + +insert into attribute VALUES + ('s1',50,65,80,30), + ('s2',12,20,25,35), + ('s3',150,225,325,24), + ('s4',50,75,120,25), + ('s5',50,100,150,40), + ('s6',100,125,150,45), + ('s7',60,100,140,35), + ('s8',150,200,500,65), + ('s9',125,150,225,34), + ('s10',110,150,300,34), + ('s11',150,200,800,65), + ('s12',100,175,285,44), + ('s13',244,344,844,60); +-- 3.查询每个星级的英雄数量,按照星级升序 +select starlevel,count(*) from heroinfo group by starlevel order by starlevel asc; +-- 4.查询1星英雄平均护甲值 +select avg(a.ac) from heroinfo h inner join attribute a on h.gameno = a.gameno where h.starlevel =1; +-- 5.为attribute添加暴击字段(critical),一星英雄初始为10%,二星15%,三星30% +alter table attribute add critical varchar(5); + +update attribute set critical = '10%' where gameno in (select gameno from heroinfo where starlevel=1); +update attribute set critical = '15%' where gameno in (select gameno from heroinfo where starlevel=2); +update attribute set critical = '30%' where gameno in (select gameno from heroinfo where starlevel=3); +-- 6.查询血量大于125的英雄姓名 +select `name` from heroinfo h left join attribute a on h.gameno=a.gameno where a.hp>125; +-- 7.烬进化失败,从表中移除 +delete from heroinfo where `name` ='烬'; +-- 8.添加英雄佛耶戈 ,(s14,‘怪兽入侵’,‘福牛守护者,混沌战士’,3,36) +insert into heroinfo values('s14','怪兽入侵','福牛守护者','混沌战士',3,36); +-- 9.查询版本为天选福星的三星英雄的属性 +select a.* from heroinfo h inner join attribute a on h.gameno=a.gameno where h.edition='天选福星'and h.starlevel=3; +-- 10.查询血量前4的英雄姓名 +select h.`name` from heroinfo h inner join attribute a on h.gameno=a.gameno order by hp desc limit 0,4; +-- 11.查询名字中有“克”的英雄信息 +select * from heroinfo h inner join attribute a on h.gameno=a.gameno where name like '%克%'; +-- 12.查询法力值在80-150之间的英雄编号 +select gameno from attribute where mp between 80 and 150; +-- 13.查询名字数为4个字的英雄信息 +select * from heroinfo where name like '____'; +-- 14.查询购买所有3星和2星共花多少费用 +select sum(cost) from heroinfo h where h.starlevel in (2,3); +-- 15.天空一声巨响,亚托克斯升为3星,攻击力提升50% +update heroinfo set starlevel=3 where `name`='亚托克斯'; +update attribute set atk=atk*(1+0.5) where gameno=(select gameno from (select a.gameno from heroinfo h inner join attribute a on h.gameno = a.gameno where h.name='亚托克斯') a); +-- 16.删除attribute表的mp字段 +alter table attribute drop mp; +``` +