mysql(五) 常用命令

1. add 添加table属性

alter table student add birthday date int(10);

这里使用了alter命令,意思是在表sudent中添加birthday这个属性,值得类型为date(1992/12/05)

2.update

 update student set birthday="1990/02/14" where id=2;

   id中第二个birthday的值更新为1990/02/14,如果不加where,那么表格中birthday所有id都设置为1990/02/14这个值

3.limit截取table中的某部分数据

select * from student limit 2;

只取前面的两个id的所有属性值。

4.排序order by

select * from student order by id desc;  ----按照id的从大到小排列输出

select * from student order by birthday asc limit 1; -----找出年龄最大者并输出

select  * from student order by birthday asc limit 1,1;-----找出年龄第二大的,这里limit的第一个值是从0开始,1表示从条件返回的值中的第二个值,limit的第二个值1表示记录个数,1表示只输出一个。

5.去重 distinct

select distinct year(birthday)as "学生出生年份" from student;

如果表格中的birthday有重复的值,通过distinct可以过滤。

你可能感兴趣的:(mysql(五) 常用命令)