create table emp(
id int comment'编号',
workno varchar(10) comment '工号',
name varchar(10) comment '姓名',
gender char comment '性别',
age tinyint unsigned comment '年龄',
idcard char(18) comment'身份证号',
workaddress varchar(50) comment '工作地址',
entrvdate date comment '入职时间')
comment '工作表'; #创建表格
insert into client(id, name, age, gender) VALUES (1,'xiajia',24,'男'); #向表格中插入值
alter table client change gender gender varchar(5); #修改表格中的字段
insert into client(gender) values ('nv'); #在字段为gender的位置插入值,其他字段未指明,为null
delete from client where test.client.gender='nan'; #删除所有在字段gender处值为'nan'的行
update client set gender = 'nan' where name='xiajia'; #将在字段name处值为'xiajia'的行的gender字段处的值修改为'nan'
delete from example_table where id=1; #删除id为1的行
update example_table set id = 1 where id=2; #将id从2修改为1
select name,age from example_table; #返回字段name、age处的所有值
select * from example_table; #返回表格中所有字段的值
select name as nickname from example_table; #返回name字段的值,用nickname代替name
use test; #使用test数据库
select database(); #返回当前正在使用的数据库
select distinct workaddress from emp; #返回字段workaddress中不重复的值
alter table emp drop workno; #删除表格emp中的字段workno与其对应的值
select * from emp where age=20; #返回字段age的值为20的所有行
select * from emp where age <= 18; #返回字段age的值小于18的所有行
update emp set age = null where id=4; #将字段id为4处的age字段处的人值修改为null
select * from emp where age is null; #返回字段age的值为null的所有行
select * from emp where age is not null; #返回字段age的值不为null的所有行
select * from emp where age != 20; #返回字段age的值不为20的所有行
select * from emp where age <> 20; #返回字段age的值不为20的所有行
select * from emp where age>=15 && age<=18; #返回字段age的值在15到18之间的所有行
select * from emp where age between 15 and 18; #返回字段age的值在15到18之间的所有行
select * from emp where age = 20 and workaddress = '西安'; #返回字段age的值为20且字段workaddress为'西安'的所有行
select * from emp where age in (18,20) and workaddress = '西安'; #返回字段age的值在(18,20)之间且字段workaddress为'西安'的所有行
select * from emp where name like '_'; #返回字段name的值为一个字符的所有行
select * from emp where name like '%x'; #返回字段age的值的最后一位为x的所有行,其中%代表任意字符长度
select MAX(age) from emp;
select count(age) from emp; #返回字段age中含有数据的个数,null不参与聚合函数的计算,(max、min、avg(平均)、sum)
select avg(age) from emp;
select sum(age) from emp where workaddress = '西安'; #返回workaddress
为'西安'的字段为age的数据的和