找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手

操作表结构命令:
1.   create databases  
2.   drop
3.   create table
4.   alter table

数据库的增删改查的命令:
select from 查询
insert into   增加
delete from  删除
update set    改


1.        ncate +表名  只是删除表数据,不会影响整个数据库的表结构
2.        p table +表名  把整个表,包括数据全部删除,
3.        te from +表名 只是删除表数据,但能指定删除哪段数据。
4.        te from +表名 +where +字段名=所需删除的行数
例:delete from test where id=5;删除test表中的第五行
       delete from test where id>5;删除test表中大于5的行数
       delete from test where id<5;删除test表中小于5的行数

更改表内容:
update test set score=100 where id=1; 将ID的第一行的成绩更改为100
id之所以通常作为条件,是因为id是唯一的。
update +表名 set +字段=值 where 条件;

select * from +表名   查询整个表

select +字段 from +表名  指定查询

select +字段,+字段 from +表名  查询多个字段

select +字段 from +表名 where +条件    只查询输入条件的某行字段
注释: “!=”或者“<>”都是”≠“的意思。

select * from +表名 where 字段=值 and 字段=值;
注释:查询同时满足多个条件的数据

select * from +表名 where 字段=值 or 字段=值;
注释:查询满足至少一个条件的数据

select * from +字段 where  字段 between 值and值;
注释:查询包含条件的数据

select * from +表名 where +字段 in(值1,值2);
注释:查询字段满足在指定的集合中的数据

select * from +表名 where +字段 not in(值1,值2);
注释:查询字段不满足在指定集合中的数据

select * from +表名 where +字段 is null;
注释:查询字段值为空的数据

select * from +表名 where +字段 is not nu;
注释:查询字段值不为空的数据

select * from +表名 where +字段 like "%值%"  ;      %:用于匹配字段开头和结尾
注释:查询某个字段模糊匹配成功的数据

select * from +表名 where +字段 limit m,n ;
注释:查询表中m到n行。m 指下标,n指限定的数量,下标为m的开始的n条数据
若m为2,n为3,表示从第二行后面开始,再查三行。

select * from +表名 order by +字段 desc ;
注释:降序排列,即从大到小进行排列。

select * from +表名 order by +字段 asc;
注释:升序排列,即从小到大进行排列。

select * from +表名 group by +字段;
注释:根据数据对字段进行分组
例子:select class ,sum(math) from student1 group by class;
先对表中的class进行分组,再求出每个班级math成绩的总和

select * from +表名 group by +字段 having 条件;
注释:查询的数据根据某个字段进行分组再条件过滤
例子:select class ,sum(math) from student1 group by class having sum(math)>70;
先对表中的class进行分组,再求出每个班级math成绩的总和,且只显示总分大于70的班级和成绩。
........sum(math)as t,..............t>70; 求出math总和,并取一个别名为t,最后用t表示math.
分享至 : QQ空间
收藏

0 个回复

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