-- 创建数据库
create database if not exists school default charset=utf8;
-- 使用数据库
use school;
-- 创建表
create table studentinfo (
id int auto_increment primary key,
name
varchar(20),
sex char,
age int ,
address varchar(50)
) default charset=utf8;
-- 插入数据
insert into studentinfo (`name` ,sex ,age ,address ) values ("张三丰" , '男' , 58 ,'武当山'),
("张无忌" , '男' , 18 ,'日月神教'),
("周芷若" , '女' , 18 ,'峨眉派'),
("赵敏" , '女' , 19 ,'蒙古'),
("小昭" , '女' , 20 ,'日月神教');
-- 模糊查询
select* from studentinfo;
-- 完整查询
select id , name
,sex ,age ,address from studentinfo;
-- 条件查询
select * from studentinfo where sex = "男";
-- 排序 ,按照年龄进行排序 ase 升序 desc 降序
select * from studentinfo order by age asc ;
-- 限制查询结果的个数
select * from studentinfo order by age asc limit 2 ;
-- 复合
select * from studentinfo where sex='女' order by age desc limit 2 ;