diff --git "a/20 \345\206\257\351\224\220/20220315 \344\275\234\344\270\232.md" "b/20 \345\206\257\351\224\220/20220315 \344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..ddbac79a43f30d228743560c182cbc16678e41a5 --- /dev/null +++ "b/20 \345\206\257\351\224\220/20220315 \344\275\234\344\270\232.md" @@ -0,0 +1,73 @@ +```mysql +create database Ok; +create database wugui charset utf8; +use wugui; +create table wugui_a( + wuguiNo int primary key auto_increment, + wuguiName varchar(50) not null , + wuguiSex varchar(20) not null , + wuguiAddress varchar(50) not null , + wuguiprice varchar(255) +); +drop table wugui_b; +create table wugui_b( + wuguiNo1 int primary key auto_increment, + wuguiRank varchar(20) not null , + wuguiWeight int not null +); +drop table wugui_c; +create table wugui_c( + wuguiType varchar(20), + wuguiNo int primary key auto_increment +); +insert into wugui_a values + (null,'周富','母','下水道',1), + (null,'赵敏大美女','公','皇宫',2500000), + (null,'杨敏小公主','母','温州',2500000), + (null,'乌龟大王谢铖浩','男','东海龟宫',1000000000), + (null,'方增兴','公','数据库',250), + (null,'林俊伟','公','花果山',251); +insert into wugui_b values + (null,'低级',250), + (null,'至尊级',2500), + (null,'高级',500), + (null,'玄武级',60000), + (null,'高级',666), + (null,'高级',500); +insert into wugui_c values + ('双面龟',null), + ('巴西龟',null), + ('蛋龟',null), + ('玄武',null), + ('巴西龟',null), + ('陆龟',null); +-- 1.查询出性别为母的乌龟 +select * from wugui_a where wuguiSex='母'; +-- 2.查询性别为公的乌龟 +select * from wugui_a where wuguiSex='公'; +-- 3.查询出每个乌龟的编号,姓名,性别,住址,价格 +select * from wugui_a; +-- 4.查询价格大于20000以上的乌龟信息 +select * from wugui_a where wuguiprice>20000; +-- 5.查询出价格低于200的乌龟信息 +select * from wugui_a where wuguiprice<200; +-- 6.查询不属于公母性别的乌龟 +select * from wugui_a where wuguiSex !='公' and wuguiSex !='母'; +-- 7.查询每个乌龟对应的等级 +select wuguiRank,wuguiType from wugui_b b,wugui_c c where b.wuguiNo1=c.wuguiNo; +-- 8.查询出品种相同的乌龟 +select wuguiType from wugui_c group by wuguiType having count(wuguiType); +select wuguiType from wugui_c where wuguiType in (select wuguiType from wugui_c group by wuguiType having count(wuguiType) > 1); +-- 9.查询字段wuguiName里面有大的名字 +select wuguiName from wugui_a where wuguiName like '%大%'; +-- 10.按乌龟的价格进行降序 +select * from wugui_a order by wuguiprice desc ; +-- 11将乌龟的品种进行去重 +select wuguiType from wugui_c where +-- 12.将rank里面的体重求平均值 +select avg(wuguiWeight) 平均值 from wugui_b group by wuguiRank; +-- 13.将info和rank表连接,然后按照rank的体重进行降序,在获取表内的前3行记录 +select * from wugui_a a,wugui_b b where a.wuguiNo=b.wuguiNo1 order by wuguiWeight desc limit 3 ; +-- 14.在13的基础上获取里面乌龟价格最高的数据 +select max(wuguiprice) from wugui_a a,wugui_b b where a.wuguiNo=b.wuguiNo1 order by wuguiWeight desc limit 3 ; +``` \ No newline at end of file