day18
两个表student和user
student id s_name s_age s_sex
user id u_name u_age u_sex
批量插入
insert into student s_name s_sex select u_name,u_sex from user;
//把user表的u_name 和u_sex字段所存储的内容插入到student表的s_name s_sex里面
模糊查询:like搭配" %" %表示任意字符,可以有也可以没有
查询student表中名字是以1开头的所有字段信息
select * from student where s_name like '1%';
#内置函数
-- 当前时间
SELECT NOW();
-- 时间日期格式化
SELECT DATE_FORMAT(NOW(),'%Y/%m/%d %h:%i:%s');
-- 拼接字符串
SELECT CONCAT('111','222','333');
-- 查看当前数据库版本
SELECT VERSION();
#聚合函数
SELECT count(*) FROM student;
SELECT sum(s_age) from student;
SELECT avg(s_age) from student;
SELECT max(s_age) from student;
SELECT ROUND(3.14159,3);
# distinct关键字
-- 1)想要对哪个字段去重,就在该字段前加distinct关键字
-- 2)distinct关键字后面跟多个字段名,表示对这些字段信息组合去重
-- 3)distinct关键字前面不能跟任何字段
SELECT DISTINCT s_age from student;
SELECT DISTINCT s_age,s_name from student;
分页查询
//查询student表的前两条信息
select*from student limit 2;
srlrct*from student limit 0, 2;
//分页查询,每页两条记录
//pageNo页码 rowCount每页展示的记录数limit (pageNo-1)*rowNo, rowNo
select*from student limit 0, 2;
select*from student limit 2, 2;
//排序
//查询所有学生信息,并按照年龄从小到大排序
select*from student order by s_age asc;
//查询所有学生信息,并且按照年龄从大到小排序
select*from student order by s_age desc;
标签:函数,distinct,age,查询,--,student,SELECT,name
From: https://www.cnblogs.com/xiaoto9426/p/16827071.html