前言:
本文内容:分页和排序、子查询和嵌套查询、MySQL常用函数
推荐免费MySQL基础讲解视频:【狂神说Java】MySQL最新教程通俗易懂_哔哩哔哩_bilibili
分页和排序
排序
1 2 3 4 5 6 7 select * from student order by `id` desc select * from student order by `id` asc
分页
当前页 n
页面大小 pageSize
起始页 (n-1)*pageSize
总页数 数据总数/页面大小
1 2 3 4 5 6 7 8 9 10 11 12 13 14 select * from student limit 0 ,5
子查询和嵌套查询
子查询
本质:在where语句中嵌套一个查询语句
1 2 3 4 5 6 select `gradeid` from `grade` where gradename= '大一' ;select `id`,`name`,`sex`,`address`,`gradename` from `student`st, `grade` g where g.gradeid= (select `gradeid` from `grade` where gradename= '大一' )= st.gradeid;
MySQL常用函数
MySQL 8.0 内置函数和运算符参考
MySQL 函数 | 菜鸟教程 (runoob.com)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 select abs (-8 ); select Ceiling (9.3 ); select floor (9.4 ); select rand(); select sign(11 ); select char_length ('代码小白哦' ); select concat('写' ,'代码' ,'是热爱' ); select insert ('写代码是热爱' ,5 ,2 ,'超级热爱' ); select lower ('JOKERDIG' ); select upper ('jokerdig' ); select instr('jokerdig' ,'k' ); select replace('baidu.com' ,'baidu' ,'jokerdig' ); select substr('写代码是热爱' ,1 ,3 ); select reverse('反转字符串' ); select * from student where `name` like '张%' ;select replace(`name`,'张' ,'刘' ) from student where `name` like '张%' ;select current_date (); select now(); select localtime (); select sysdate(); select Year (NOW()); select system_user (); select user ();select version();