MySQL查询命令

1、select * from+数据表

2、查询表指定数据记录列

3、查询不重复

4、查询区间

例1

查询user表中id在2-3的记录

或者使用命令select * from user where id >2 and id < 3;也可以实现。

例2

查询user表中id为1或3的记录

或者使用命令select * from user where id=1 or id=3;

5、以id降序查询user表

6、以id升序(主),name降序排列(次)

7、统计人数

统计id=1的人数

8、统计id最高的name名

9、查找前几位

注:limit函数前一个数字是从多少位开始,第二个数字是查找多少位

10、查询id的平均数

注:查询name为ajin的平均id和name为zhang的平均id

命令:select avg(id) from user where name="ajin";

select avg(id) from user where name="zhang"

或者将两个命令合为一起

select avg(id) from user group by name(group by的作用是先将name进行分组)

11、查询name以a开头的记录

注:like函数的使用

更多推荐

MySQL查询命令