找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
删除
truncate student;   删除表数据,不删除表和表结构
drop table 表名; 同时删除
delete from 表名;只删除数据
delete from 表名 where id=5; 删除id=5这个数据
delete from 表名 where id>7; 删除id=7后面的所有数据
修改
update 表名 set score=100 where id=1;改某个字段数据的数据 where后面接条件一般改id(将id1的score改成100)
update 表名 set name=‘xiaoluo‘ where  id>2;将id大于2的name改成xiaoluo

查询

select * from 表名;查询整个表的数据和字段
select name,time from 表名;查询两个字段的数据
select name from 表名 where id=3;查询id等于3,且只显示name的数据
select * from 表名  
select * from 表名 where class=1835 and name=‘wangwu’;查询同时满足多个条件
select * from 表名 where class=1833 or class=1835;查询满足至少一个条件的数据or一般用在筛选一个字段
select * from 表名 where age between 25 and 31;查询一个条件范围的数据,between,and指定范围
select * from 表名 where class in(1833);查询数据满足指定的集合里面,in在什么里面
select * from 表名 where class in(1833,1835);能同时查询到1833和1835
select * from 表名 where classnot in (1833,1835);not in 不在这个集合里面
select * from 表名 where class is null;查询某个字段值是空的数据,null不是一个值,是空的属性
select * from 表名 where class is not null;查询不是一个空的属性
select * from 表名where name like ‘xiao‘%;查询某个字段模糊匹配成功的数据 ,like像的意思,%用于匹配开头和结尾
select * from 表名 where id limit 0,5;查询id数据0-5行的数据前五行的数据
select * from 表名 where id limit 2,3;查看到3到5行的数据,从第2行开始,查询到后面三行的数据
select * from 表名 where order by age desc;查询到的数据从大到小排序,order by排序,desc降序
select * from 表名 where order by age asc;查询到的数据从小到大排序,order by排序,asc升序
select sum(math)from 表名;对sum求和
select sum(math) from 表名 group by class;对每个班先进行分组,在求和,group by分组
select sum(math),class from 表名 group by class;sum(math),class代表一般分组的字段,要作为显示字段。group by代表分组
select sum(math),class from studentl group by having sum(math)>100;haaving相当于where后面接条件,把表先对班级进行分组,求出每个班级的数学成绩求和,且显示总分大于100分的班级和分数
select sum(math)as t,class from 表名 proup by class having t>100;sum(math)as t求和的总成绩取别名t
select sum(math) t,class from 表名;后面没接条件不能把字段和函数作为显示字段s
分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册