1.创建表:create table stu(id int(10) primary key auto_increment, sname char(30) not null, sex tinyint(1) default 0,qq varchar(255)) default character setutf-8 engine mysisam;
2.insert into stu(sname,sex,qq) valuer("李玉",1,3287832); -------------
3.select sname from stu where sname="李玉"; select sname from stu where sname like"%李%";
4.select if(sex,"男生","女生") , sname from stu; select if(sex,"男生","女生") as “性别” , sname from stu; select if(sex,"男生","女生") as “性别” , sname from stu where sname like "李%" and sex=0; select if(sex,"男生","女生") as “性别” , sname from stu where sname like "李%" or sex=0;
5.select concat ("姓名:",sname,"姓名:",sex,"qq",qq) as stuinfo from stu;
6.select concat ("姓名:",sname,"姓名:", if(sex,"男","女"),"qq",qq) as stuinfo from stu;
7.添加字段:alter table stu add birday date int(10);
8.update stu set birday = "1000/2/23";
9.取部分数据:select * from stu limit 2; select * from stu order by id desc limit 2; select * from stu order by id desc limit 0,5;
10.select * from stu where birday <= "1990/12/12"; select * from stu where birday <= (select birday from stu order by birday limit 1,1);
11.查看年份 select year(birday) from stu; 去重复select distinct year(birday) as “出生年” from stu;、
12.查询几个最大