Mysql 查询,删除

 

//查看表的内容

select * from hpeu_student;

//从第一行查找五行

select * from hpeu_student limit 5;

 

 

//从第一行的下零行查找5行

select * from hpeu_student limit 5 offset 0;

//从第一行的下一行查找5行

select * from hpeu_student limit 5 offset  1;

select * from hpeu_student limit 1,5;

 

//where 后面指定条件 stu_id<4 and stu_name='jim';where通常把小表放在前面,范围小提高效率

select * from hpeu_student where stu_id = 4;

 

//like的用法:stu_id 含有5的 而且 stu_name含有uc的

select * from hpeu_student where stu_id like '%5%' and stu_name like '%o%';

 

//order by  排序(desc降序 asc升序)  stu_id含有1的按照 stu_name升序排序

select * from hpeu_student where stu_id like '%1%' order by stu_name asc;

 

//group by 分组 两次筛选后面加 order by 字段 单个必须把name作为主要字段,加入order by可以加多个字段

select * from hpeu_student where stu_id <5 group by stu_name;

select stu_id,stu_name from hpeu_student where stu_id <5 group by stu_name;//报错count(str_id)就不会报错 count(str_id) as id 起别名id

 

//having(分组条件) 针对order by 分组之后的再筛选条件,行过滤

select * from hpeu_student where stu_id <5 group by stu_id having stu_id=3;

 

//更新数据 set 后面可以有多个更改,where是条件,没有就会全部更改

update table set stu_name='Mike'  where stu_id=1;

 

//删除数据库(真正的环境中通常都不使用drop)

drop database Test

//删除表,删除表结构,必须要从新 新建表

drop table hpeu_student;

//删除表的全部内容,不删除表结构,不能与where一起使用,删除索引,stu_id会从1开始

truncate hpeu_student;

//delete 删除可以where 加条件删除,不会删除索引,stu_id会从后面开始

delete hpeu_student where stu_id>4;

 

posted @ 2018-08-06 17:32  从不曾明白  阅读(2972)  评论(0编辑  收藏  举报