MySQL的基本查询 1:创建表格create table student(id int(5),name varchar(22),age int(5),class varchar(22)); 2:插入数据 insert into student(id,name,age,class) v……
MySQL的基本查询
1:创建表格
create table student(
id int(5),
name varchar(22),
age int(5),
class varchar(22)
);
2:插入数据
insert into student(id,name,age,class) values(‘1’,‘张三’,18,‘NIIT一班’);
insert into student(id,name,age,class) values(‘2’,‘李四’,20,‘NIIT二班’);
insert into student(id,name,age,class) values(‘3’,‘王五’,22,‘NIIT三班’);
insert into student(id,name,age,class) values(‘4’,‘张宗旺’,24,‘NIIT四班’);
3:基础查询:
select name from student; 查询单个字段
加粗样式select name,class,age from student; 查询多个字段
select * from student; 查询所有
4:利用别名查询
select name as 姓名 from student; 例如,想查询姓名
5:去重
select distinct age from student; 去除查询age的重复元素
6:条件查询
select * from student where age > 20; 查询年龄大于20的字段
7:模糊查询
select * from student where name like ‘张%’; 查询名字以“张”子开头的字段
8:排序查询
①:asc 升序排序 ②:desc 降序查询 order by 支持多种
select * from student order by age desc; 降序
select * from student order by age asc; 升序
还没有评论呢,快来抢沙发~