同步滾動:關
SQL的基礎函數
lower
select lower(name) from students #將students表的所有name字段的數據全都轉為小寫打印出來
upper
select upper(name) from students #將students表的所有name字段的數據全都轉為大寫打印出來
length
select length(name) from students #將students表的所有name字段的數據的長度打印出來
substr
select substr(name,1,3) from students; #name字段從1的位置向后截取3位打印出來 例如David -->Dav
select substr(name,2,3) from students; #name字段從2的位置向后截取3位打印出來 例如David -->avi
注意:sql的下標是從1開始
concat
select concat(name,'123') from students; #將students表的所有name字段的數據后面拼接123打印出來 例如David -->David123
replace
select replace(name,'a','666') from students; #將students表的所有name字段的數據中的a替換為666 例如David -->D666vid
ifnull
select ifnull(hobby,'學習') from students #判斷,如果hobby字段的值是null的用學習替換
round & ceil & floor
select round(score) from students #四舍五入取整
select round(score,1) from students #四舍五入,保留一位小數
select ceil(score) from students #向上取整 7.1 --> 8
select floor(score) from students #向下取整 7.9 --> 7
now
select now() #現在的年與日,時分秒
select curdate() #現在的年月日
select curtime() #現在的時分秒
year & month & day
select year(now()) #取現在的年
select month(now()) #取現在的月
select day(now()) #取現在的日
hour()時&minute()分&second()秒
select hour(now()) #取現在的時
select minute(now()) #取現在的分
select second(now()) #取現在的秒
標簽: [數據庫]






