Query OK, 0 rows affected (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 0
修改默认值为20:default 20;
.格式:insert into 表名 [(字段列表)] values(值列表)[,(值列表),(值列表)]
标准添加sql,指定所有字段,给定所有值'
指定部分字段,给定部分值添加
不指定字段添加值 要注意顺序和个数
mysql> insert into stu values(null,'wangwu',25,'w','python03');
.格式: delete from 表名 [where 条件[分组.排序.limit]]
.删除id为20的信息: delete from stu where id=20;
.删除id在100到200之间的信息:
delete from stu where id between 100 and 200;
或
delete from stu where id>=100 and id<=200;
.格式:update 表名 set 字段名1=值1[,字段名2=值2][where 条件]
.将id为9和11的年龄改为23,班级classid改为python03
update stu set age=23,classid='python03' where id in(9,11);
输出时:
.查询时可以给字段名起别名:
mysql> select id,name as username,age from stu;
.追加一个字段:
mysql> select *,age+5 age5 from stu;
.增加新字段:
mysql> select *,'shanghai' city from stu;
.将两个字段连成一个字段进行输出:concat
mysql> select concat(classid,":",name) from stu;
where条件查询
.两者之间用and 两者之外用or
.查询为空的: is null
mysql> select * from stu where classid is null;
.like 模糊查询 % _
% 表示任意数量的任意字符;
_ 表示一个字数的任意字符;
查询姓名中含有an子串的所有信息:
select * from stu where name like '%an%';
select * from stu where name regexp 'an';
.统计函数 聚 合函数
max() min() sum() avg() count()
最大 最小 总和 平均值 总计
select max(age),min(age),sum(age),avg(age),count(id) from stu;
group分组查询: group by 字段名 分组
.按照性别分组:
select sex,count(*) from stu group by sex;
.班级分组除空:
mysql> select classid,count(*) from stu where classid is not null group by classid;
.按照班级分组,并且统计每个班级的男生和女生人数
select classid,sex,count(*) from stu where classid is not null group by classid,sex;
评论0
最新资源