您的位置:首页 > 数据库 > MySQL

Mysql中id自增的基础语句

2011-04-21 11:24 253 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: