MySQL之常用函式

2021-10-06 12:48:47 字數 1748 閱讀 8471

數學函式主要是對數值型資料進行處理。

向上取整函式:select ceiling(3.12)

向下取整函式:select ceiling(3.12)

四捨五入函式:select round(3.12,1)

截斷小數字:select truncate(3.1233434,2)

返回pi值:select pi()

隨機數:select pi()

列轉行案例

create table `mystudent` (

`id` int(10) not null auto_increment,

`user_name` varchar(20) default null,

`course` varchar(20) default null,

`score` float default '0',

primary key (`id`)

)insert into mystudent(user_name, course, score) values

("張三", "數學", 34),

("張三", "語文", 58),

("張三", "英語", 58),

("李四", "數學", 45),

("李四", "語文", 87),

("李四", "英語", 45),

("王五", "數學", 76),

("王五", "語文", 34),

("王五", "英語", 89);

select user_name 姓名,

max(case course

when '語文'

then score

else 0

end) 語文,

max(case course

when '數學'

then score

else 0

end) 數學,

max(case course

when '英語'

then score

else 0

end) 英語

md5本質是乙個雜湊函式,是不可逆的。

mysql之常用函式

用於處理字串的函式 用於處理數值的函式 用於處理時間日期的函式 首發日期 2018 04 14 實驗表資料 下面的執行資料基於這個表 create table student name varchar 15 gender varchar 15 age int insert into student ...

MySQL之常用函式

用於操作的資料庫表 聚集函式 用於處理字串函式 用於處理字串的函式 合併字串函式 select concat str1 str2 str3 合併字串函式 select strcmp str1 str 獲取字串位元組數函式 select length str1 獲取字串字元數函式 select cha...

MySQL之常用函式

mysql有如下常用函式需要掌握 1 數學類函式 函式名稱 作用 abs x 返回x的絕對值 sqrt x 返回x的非負二次方根 mod x,y 返回x被y除后的餘數 ceiling x 返回不小於x的最小整數 floor x 返回不大於x的最大整數 round x,y 對x進行四捨五入操作,小數點...