-- 創(chuàng)建數(shù)據(jù)庫(kù)
create database if not exists school default charset=utf8;
-- 使用數(shù)據(jù)庫(kù)
use school;
-- 創(chuàng)建表
create table studentinfo (
id int auto_increment primary key,
name
varchar(20),
sex char,
age int ,
address varchar(50)
) default charset=utf8;
-- 插入數(shù)據(jù)
insert into studentinfo (`name` ,sex ,age ,address ) values ("張三豐" , '男' , 58 ,'武當(dāng)山'),
("張無(wú)忌" , '男' , 18 ,'日月神教'),
("周芷若" , '女' , 18 ,'峨眉派'),
("趙敏" , '女' , 19 ,'蒙古'),
("小昭" , '女' , 20 ,'日月神教');
-- 模糊查詢
select* from studentinfo;
-- 完整查詢
select id , name
,sex ,age ,address from studentinfo;
-- 條件查詢
select * from studentinfo where sex = "男";
-- 排序 距淫,按照年齡進(jìn)行排序 ase 升序 desc 降序
select * from studentinfo order by age asc ;
-- 限制查詢結(jié)果的個(gè)數(shù)
select * from studentinfo order by age asc limit 2 ;
-- 復(fù)合
select * from studentinfo where sex='女' order by age desc limit 2 ;