/*日期函数*/


select year(now()); #返回年份


select month(localtime);#返回月份


select sysdate(); #返回当前时间


select(localtime);#返回当前时间,注:now()、localtime()、localtime、sysdate()


select now(); #返回当前时间


select monthname(now()); #返回月份的英文名


/*数值函数*/


select truncate(3.9999,2); #truncate(x,y),x是小数,y是取x的几位数


select abs(-3.99); #取绝对值


select rand(); #获取0-1之间的随机数


select floor(9 + (rand() * 8));   #若要在i ≤ R ≤ j 这个范围得到一个随机整数R ,需要用到表达式 FLOOR(i + RAND() * (j – i + 1))

 

/*流程函数*/


1、if(expr1,expr2,expr3)  expr1如果为true,则返回expr2,如果为false,则返回expr3

示例:select if(age=20,100,age)from user;

 

2、IFNULL(expr1, expr2)   如果expr1不为空,则返回expr1,为空则返回expr2的值

示例:select ifnull(username,"空") from user;

 

3、case when (value) then (result) else (default) END


示例:select case when age>27 then "最大" else age end from student;

 

相关文章:

  • 2021-05-26
  • 2021-09-11
  • 2021-07-24
  • 2021-12-07
  • 2022-02-07
  • 2021-08-25
  • 2021-07-14
猜你喜欢
  • 2022-03-07
  • 2023-03-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2021-04-16
相关资源
相似解决方案