MySql(八)
目录
查询
1)准备一张表
2)准备数据
3)查询表中的数据
4)只查表中的某些列
5)为列起别名
使用 as
不使用as
查询
1)准备一张表
CREATE table role(
roleid INT PRIMARY KEY AUTO_INCREMENT,
rolename VARCHAR(200),
roleskill VARCHAR(300),
rolesex CHAR(1),
rolemonkey int,
roleinfo VARCHAR(200),
rolehealth INT
);CREATE table role(roleid INT PRIMARY KEY AUTO_INCREMENT,rolename VARCHAR(200),roleskill VARCHAR(300),rolesex CHAR(1),rolemonkey int,roleinfo VARCHAR(200),rolehealth INT );
2)准备数据
INSERT into role VALUES
(null, '小玖', '暗影', '女', 500000, '猎手', 50000),
(null, '暗色', 'coc', '男', 60000, '骑士', 50000),
(null, '黎明', '曙光', '女', 70000, '战士', 50000),
(null, '雪夜', '银色', '男', 30000, '猎人', 50000),
(null, '张久', '酒心', '女', 50000, '肉盾', 50000),
(null, '雪色', '雪风', '男', 50000, '女魔', 50000),
(null, '安久', '蛋定', '女', 50000, '魔法士', 50000);INSERT into role VALUES (null, '小玖', '暗影', '女', 500000, '猎手', 50000), (null, '暗色', 'coc', '男', 60000, '骑士', 50000), (null, '黎明', '曙光', '女', 70000, '战士', 50000), (null, '雪夜', '银色', '男', 30000, '猎人', 50000), (null, '张久', '酒心', '女', 50000, '肉盾', 50000), (null, '雪色', '雪风', '男', 50000, '女魔', 50000), (null, '安久', '蛋定', '女', 50000, '魔法士', 50000);
3)查询表中的数据
select * from role;
4)只查表中的某些列
例如我们只想看某些列
select 列名1, 列名2, 列名3 from 表名;
select roleid, rolename, roleskill from role;
5)为列起别名
使用 as
select 列名 as 别名, 列名2 as 别名2... from 表名;
SELECT roleid as 角色id, rolename as 角色名字, roleskill as 角色技能, rolesex as 性别, rolemonkey as 角色金钱, roleinfo as 角色信息, rolehealth as 角色健康值
from role;
SELECT roleid as 角色id, rolename as 角色名字, roleskill as 角色技能, rolesex as 性别, rolemonkey as 角色金钱, roleinfo as 角色信息, rolehealth as 角色健康值from role;
不使用as
select 列名 as 别名, 列名2 as 别名2... from 表名;
SELECT roleid 角色id, rolename 角色名字, roleskill 角色技能, rolesex 性别, rolemonkey 角色金钱, roleinfo 角色信息, rolehealth 角色健康值
from role;
SELECT roleid 角色id, rolename 角色名字, roleskill 角色技能, rolesex 性别, rolemonkey 角色金钱, roleinfo 角色信息, rolehealth 角色健康值from role;