创建表:
CREATE TABLE student(student_no INT NOT NULL PRIMARY KEY AUTO_INCREMENT,login_pwd VARCHAR(20),stu_name VARCHAR(20),sex TINYINT,grade_id INT ,phone VARCHAR(25) NOT NULL ,address VARCHAR(255) NOT NULL,borndate DATE,emial VARCHAR(50),`identified` VARCHAR(18));
添加数据:
insert into student values(null,'abc','王五',0,2,'13800000000','上海市浦东区','1993-3-26','lisi@163.com','210326199303261118');
计算两个人的总年龄:
SELECT sum(age)`总共年龄` FROM student;
SELECT avg(age)`平均年龄` FROM student;
SELECT max(age)`最大年龄` FROM student;
SELECT min(age)`最小年龄` FROM student;
select stu_name from student where not (age<23);//查询年龄不小于(大于等于)23的学生名字
select stu_name from student where age<>23;//查询年龄不等于23的学生名字
select student from student where stu_name ='周八' and age=19;//查询名字为周八并且年龄等于19的学生信息
select student from student where stu_name ='周八' or age=19;//查询名字为周八或者年龄等于19的学生信息
select age+20,grade id+2 from student where stu_name ='张三';//计算并显示张三的年龄和班级
select * form student where age between 19 and 23;//查询年龄在19到23之间的学生名字
select * from student from where student_no in(1,3,5);//查询id等于1、3、5的学生信息
select * from student from where name like `周%`;//模糊查询,名字以"周"这个字开头的数据
select * from student from where name like `%六%`;//模糊查询,查询名字中带有"六"的学生信息
修改表名
alter table 旧表名rename as 新表名
alter table student rename as student1
修改某一字段类型
alter table person modify uid int();
修改某一字段名称;
alter table person change ui _id int();