删除---delete
delete from 表名 where id=7;==指定删除表数据
delete from 表名 where id>=5;==删除id大于等于5的数据
delete from 表名==》删除全表数据
drop table test:删除表结构和表数据
trncate test;==一次删除全表数据,不能删除部分数据
delete删除的数据能恢复
修改:update
update zh set phone=13277777777 where id3=1;==)修改id=1的phone字段
查询:select
select * from 表名;===查询表中所有数据
select * from 表名 where name=”chenhan“;查询表中名字叫chenhan的表数据
select id from hhh;==指定查询表中id的数据
select * from hhh where phone!=1327748888;==查询表中手机号不等于1327748888的数据
select * from hhh where phone<>=1327748888;==查询表中手机号不等于1327748888的数据
select * from hhh where name="chenhan1" and phone=1327788888;==查询name为chenhan1及phone为1327788888的表数据,同时满足多个条件使用and。
select * from hhh where name="chenhan1" or phone=13344788888;==查询name为chenhan1或phone为1327788888的表数据
select * from hhh where id between 1 and 4;==查询id1到4之间的数据
select * from hhh where id >=1 and id<=4;==查询id1到4之间的数据
select * from hhh where phone in(1327748888,1327777999);==
select * from hhh where phone not in(1327748888,1327777999);==
select * from hhh where name like "chen%";==查询name以chen开头的字段
select * from hhh where name like "%han";==查询name以han结尾的字段
select * from hhh where name like "%chen%";==
limit m n====m-1,n-m+1(m为)
select * from hhh limit 1,2;查询2到3的数据
排序
asc 从小到大----升序
select *from hhh order by id desc;
desc 从大到小---降序
select * from hhh order by id arc;
通过class字段进行分组,然后加条件soce=98
常用的聚合函数
count()---统计
sum()--求和
avg()--求平均
min()--求最小
max()---求最大
distinct()--去重
select count() from hhh;统计
select sum(soce) from hhh;求全部班级分数之和
select sum(soce) from hhh where class=18;求18班的分数之和
select min(name) from chenhq;查询数据name最小值
select max(name) from chenhq;;最大
select distinct(phone) from chenhq;去重表数据
1、查询1832班的成绩信息
select chinese,english,math from humazi where class="1832";
2,查询1833班,语文成绩大于80小于90的成绩信息
select chinese,english,math from humazi where class=1833 and chinese >80 and chinese<90;
3,查询学生表中5到10行的数据
select * from humazi limit 4,6;
4,显示1832班英语成绩为98,数学成绩为77的姓名与学号,
select sid,name from humazi where class=1832 and english=98 and math=77;
5,查询出1832班成绩并且按语文成绩排序(降序)
select class,chinese,english,math from humazi where class=1832 order by chinese desc;
6,查询1833班与1832班,语文成绩与数学成绩都小于80的姓名。
select name from humazi where class in (1832,1833) and chinese<80 and math<80;
7,查询出没有参加语文考试的学生姓名和班级名称。
select name,chinese,class from humazi where chinese is null;
8,求出班上语文成绩不及格的学生姓名
select name from hahaha where chinese<60 or chinese is null;
9,求出每个班的数学平均成绩
select class,avg(math) from humazi group by class;
10、求出每个班级语文成绩总分 --涉及到每个的时候都需要分组
select sum(chinese),class from humazi group by class;
11、将语文成绩不及格的学生成绩改为60分
update humazi set chinese=60 where chinese<60 or chinese is null;
12、三科分数都大于70分的人名和年纪
select name,age,chinese,english,math from humazi where chinese>70 and english>70 and math>70;
13、求出英语分数高于70且其它任何一科目大于60分的人和班级
select name from humazi where english>70 and (math>60 or chinese>60);
14、统计每个班的人数
select count(class),class from humazi group by class;
15、求每个班数学成绩大于80的人数
select count(class),class,math from humazi where math>80 group by class;
16、求出每个班英语成绩最高的那个人的姓名和班级名称 --每个班英语成绩 最高
select class,name from humazi where (class,english)in(select class,max(english) from humazi group by class);
|
|