1、 要实现id的自增,要保证id是主键、int型、当然主键肯定不能为空。关键 字是auto_increment。
那么就先建一个table来看一下:
create table user(id int not null primary key auto_increment,name character(255),password character(255),email character(256));
如此就可以完成id自增的一个数据库表了。要注意,character中的最大值是255。
2、数据库查询学生成绩按排名排列:
基本数据时这样的,最终的查询结果是如下:
查询语句是:
select * from (select a.name,a.age,a.score,(select count(id)+1 from stude nt where score >a.score) as mingci from student a) b where b.mingci <= 10 order by b.mingci;