1.查询 select
1.1去重查询 distinct
select distinct 列名 from 表名;
举例:select distinct math from exam;
在exam里面去重查询math;
1.2排序 order by
select * from [表名] order by (列名) desc;
举例:select * from exam order by math desc;
使用order by 指定某一列进行排序,默认升序,asc也是升序; 显式加上desc 就是降序;
1.3条件查询(重要)where
运算符
and/or and优先级高于or
范围查询:between and
模糊查询:like
NULL查询(可以把为空的情况筛选出来)
这里举例范围查询这个例子:
select name,chinese from exam where chinese between 80 and 90;
查找语文成绩在80到90之间的学生;
1.4分页查询 limit
select * from [表名] limit n offset s;
在表里从s开始,筛选n条结果;
举例:select name,chinese+english+math as total from exam order by total desc limit 3;
找出总成绩前三名的学生
2.修改 update
update [表名] set 列名=[修改的值] where name=[被修改的学生姓名] ;
举例:update exam set math=90 where name='jerry';
修改学生jerry的数学成绩为90;
3.删除 delete
delete from [表名] where [筛选条件];
删除的时候,表存在,但是内容被删除,慎重删除!
4.新增
insert into [表名] (列名) values (要插入的值),(要插入的值);
这里新增就不细讲了,具体的参考MySQL1;
|