一,创建数据表----DDL语句
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '学号',
`cD` datetime DEFAULT NULL COMMENT '创建日期',
`name` varchar(20) DEFAULT NULL COMMENT '用户名',
`pwd` varchar(56) DEFAULT NULL COMMENT '密码',
`phone` varchar(11) DEFAULT NULL COMMENT '手机号',
`age` int(3) unsigned DEFAULT NULL COMMENT '年龄',
`sex` varchar(2) DEFAULT NULL COMMENT '性别',
`jieshao` varchar(255) DEFAULT NULL COMMENT '简介',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
二,插入数据-----DML语句
insert into student VALUES(0,'2000-02-24 10:10:10','冯诺依曼','123456','12228765499',102,'男','教育科研工作者');
insert into student VALUES(0,'2000-02-24 10:10:10','余胜军','123456','18888888888',102,'男','Java之父中国分父');
insert into student VALUES(0,'2000-02-24 10:10:10','黄仁勋','123456','12275869355',102,'男','皮衣哥');
insert into student VALUES(0,'2000-02-24 10:10:10','苏姿丰','123456','12596374185',102,'女','AMD yes!!!!!!!!!!!!!!!');
insert into student VALUES(0,'2000-02-24 10:10:10','奥特曼','123456','85596741285',102,'男','宇宙超人');
insert into student VALUES(0,'2000-02-24 10:10:10','佐菲','123456','93371525255',102,'男','队长');
insert into student VALUES(0,'2000-02-24 10:10:10','赛文','123456','99928765499',102,'男','7爷');
insert into student VALUES(0,'2000-02-24 10:10:10','八八尔','123456','12444465499',102,'男','宇宙人');
#insert into 表名 value(内容)
三,基础查询语句-------DQL
# 基础查询
select * from student;
# 筛选列(匿名)与筛选数据行
select userName as 姓名,age '年龄',sex '性别',introduce '简介'
from student
where pwd is not null;
# 分页 limit·有两个重载函数常用,
# 1、一个参数为显示条数
# 2、一个参数为从那条开始查询(下标从0开始计算),零一参数为显示条数
select * from student limit 3,2;# 从4(0-3)开始查询查2条。
# 排序,order by根据数值类型进行排序会比较准确。
select * from student order by age desc limit 3;
# 去重语句distinct
select distinct sex '性别类型' from student;