码迷,mamicode.com
首页 > 数据库 > 详细

mysql基础sql语法联系

时间:2020-07-03 19:13:13      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:攻击   英雄   ima   update   诸葛亮   enum   角色   lin   mys   


create table sanguo(
id int primary key auto_increment,
name varchar(30),
gender enum(‘男‘,‘女‘),
country enum("魏","蜀","吴"),
attack smallint,
defense tinyint
);

insert into sanguo
values (1, ‘曹操‘, ‘男‘, ‘魏‘, 256, 63),
(2, ‘张辽‘, ‘男‘, ‘魏‘, 328, 69),
(3, ‘甄姬‘, ‘女‘, ‘魏‘, 168, 34),
(4, ‘夏侯渊‘, ‘男‘, ‘魏‘, 366, 83),
(5, ‘刘备‘, ‘男‘, ‘蜀‘, 220, 59),
(6, ‘诸葛亮‘, ‘男‘, ‘蜀‘, 170, 54),
(7, ‘赵云‘, ‘男‘, ‘蜀‘, 377, 66),
(8, ‘张飞‘, ‘男‘, ‘蜀‘, 370, 80),
(9, ‘孙尚香‘, ‘女‘, ‘蜀‘, 249, 62),
(10, ‘大乔‘, ‘女‘, ‘吴‘, 190, 44),
(11, ‘小乔‘, ‘女‘, ‘吴‘, 188, 39),
(12, ‘周瑜‘, ‘男‘, ‘吴‘, 303, 60),
(13, ‘吕蒙‘, ‘男‘, ‘吴‘, 330, 71);

 

1. 查找所有蜀国人信息,按照攻击力排名
select * from sanguo where country=‘蜀‘ order by attack;
2. 将赵云攻击力设置为360,防御力设置为70
update sanguo set attack=360 where name=‘赵云‘;
3. 吴国英雄攻击力超过300的改为300,最多改2个
update sanguo set attack=300 where attack>300 and country=‘吴‘ limit 2;
4. 查找攻击力超过200的魏国英雄名字和攻击力,并且显示为姓名 攻击力
select name 名字,attack 攻击力 from sanguo where attack>200 and country=‘魏‘;
5. 所有英雄攻击力按照降序排序,如果攻击力相同则按照防御降序排序
select * from sanguo order by attack Desc,defense desc;
6.查找所有名字为3个字的英雄
select * from sanguo where name like "___";
7. 查找比魏国最高攻击力的人攻击力还要高的蜀国英雄
select * from sanguo where country=‘蜀‘ and attack>(select attack from sanguo where country=‘魏‘ order by attack desc limit 1);
8. 找到魏国防御力排名前2的英雄
select * from sanguo where country=‘魏‘ order by defense desc limit 2;
9. 找到所有女性角色,同事找到所有男性角色中攻击力不到250的
select * from sanguo where gender=‘女‘ UNION select * from sanguo where gender=‘男‘ and attack<250;

mysql基础sql语法联系

标签:攻击   英雄   ima   update   诸葛亮   enum   角色   lin   mys   

原文地址:https://www.cnblogs.com/yongqi-wang/p/13232145.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!