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;
那么就先建一个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;
相关文章推荐
- MySql基础-DDL语句
- mysql中sql语句基础
- mysql基础语句
- 数据库基础知识及MySQL语句的使用
- [androdi基础知识] 之十六: ((TelephonyManager)paramContext.getSystemService("phone")).getDeviceId();语句的理解
- MySql基础笔记(二)Mysql语句优化---索引
- 基础sql语句总结(mysql)
- MySQL的部分基础语句
- SQL基础学习(五)- MySQL的select语句
- 《MySQL基础语句及命令大全*图文一》
- mysql使用基础 sql语句与数据完整性(二)
- php操作mysql语句基础应用
- Mysql基础入门-SQL_DDL语句
- mysql基础-- 一条请求执行多条SQL语句
- MySQL基础语句【学习笔记】
- 复习篇--mysql 基础语句
- mysql分析sql语句基础工具 —— explain
- mysql基础之操作语句
- MySQL管理一些基础SQL语句
- 熟悉java堆内存和栈内存和mysql的insert语句中含有id的处理