SQL学习笔记(七):Mysql基本函数

83 阅读1分钟

具体都可以见mysql 操作手册: dev.mysql.com/doc/refman/…

1. Numeric Functions(数值函数)

image.png image.png

2. String Functions(字符串函数)

image.png image.png

3. Date Function (日期函数)

截屏2023-02-12 15.23.35.png

select year(now) 提取当前时间的年份

4. Formates Dates and Times (格式化日期时间)

select time_format(now(),%,%)

截屏2023-02-12 17.25.40.png

5. Caculating Dates and Times(计算日期时间)

增加/减少: Date_add/Date_sub image.png

返回两个日期的间隔数:

image.png

time_to_sec(now):反映从0点开始消逝的秒数

6. The IFNULL and COALESCE Functions

  • IFNULL: 用‘’代替空值的情况
image.png
  • COALESCE:返回括号中的第一个非空值
image.png

🌰:

image.png image.png

7. The IF Functions

image.png image.png

也可以写2个select 再用union 合并

8. The CASE Operator

case
when...
when...
else
end
image.png