1、像表中插入数据的格式: insert into 表名 values 数据
还是以成绩表为例,如:
insert into exam_score values (1,'Zhao',98.88),(2,'Qian',80.98),(3,'Sun',70.20),(4,'Li',60.05);
2、查看表中数据
select * from exam_score;
3、如果我想获取班级内学号前两位的同学该怎么办呢?
select * from exam_score order by id asc limit 0,2;
或者
select * from exam_score limit 0,2;
order by:根据……排序;我们可以将任意字段作为排序的条件,它默认是按照升序排列的;
那如果我们想要用降序排列呢?格式为:select * from 表名 order by 字段名 desc;
那,升序呢? 格式为:select * from 表名 order by 字段名 asc;
4、如果我想获取班级里名字叫做’Li’/id为3的同学该怎么办呢?
select * from exam_score where name = 'Li';
select * from exam_score where id = 3;
5、好,现在班级中又来了一位名字叫‘Zhao’的同学,不过他的成绩不好,我要查询这个同学的数据该怎么办呢?
1)来了一位新同学,插入数据:
insert into exam_score values (5,'Zhao',45.65);
select * from exam_score where name = 'Zhao' and score < 60;