当前位置:网站首页>Introduction and advanced level of MySQL (9)
Introduction and advanced level of MySQL (9)
2022-07-28 18:43:00 【Xiaoxinai programming】
1、 Built in functions
Function name Example The functionality
Concat concat(s1,s2…sn) Pass ⼊ Parameter connection assembly of ⼀ A string .
Length length(‘hello world’) The result is 11 Return string ⻓ degree
Upper upper(‘abcd’) Return to ABCD Convert the string to ⼤ Write
Ltrim Ltrim(‘ abc’) Return to ’abc’ Remove the space to the left of the string
Rtrim Rtrim(‘abc ’) Return to ’abc’ Remove the space to the right of the string
Replace Replace(‘abcccd’,‘c’,‘x’) Return to ’abxxxd’ take abcccd in c Replace with x
Locate Locate(‘a’,‘helloaaa’) return 6 return ⼦ strand a In string helloaaa The first ⼀ There are four positions , Returns if it does not exist 0
Substring substring(‘Johnson’,5,3) Return to ‘son’ From 5 I'm starting to intercept ⻓ Degree is 3 String
Now now() Returns the current time of the system Returns the current time of the system
TIMESTAMPDIFF TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2)
example :
SELECT TIMESTAMPDIFF
(MONTH,‘2009-09-01’,‘2009-10-01’);
return 1
return ⽇ Period or ⽇ Integer difference between period time expressions
unit It can be : MICROSECOND
(microseconds), SECOND, MINUTE,
HOUR, DAY, WEEK, MONTH,
QUARTER, YEAR.
DateAdd DATE_ADD(‘1998-01-02’, interval 1
YEAR)
return 1999-01-02
Want to ⽇ Add numbers to the specified part of the period , among :YEAR
It means year ,month Express ⽉,day Table is ⽇
Dayofweek dayofweek('2008-08-08‘) return 6
dayofweek:(1 = Sunday, 2 = Monday,
…, 7 = Saturday)
return ⼀ Mid week position
DateDiff select datediff(‘2008-08-08’, ‘2008-08-
01’); The result returned to 7
Two ⽇ Period minus date1 - date2, Return days
Date date(‘2008-09-10 07:15:30’);
return 2008-09-10
Returns a... As a string ⽇ Period part .
Abs Abs(-1) Return to ”1” Find the absolute value
Ceiling Ceiling(24.1) The result returned to 25 ⼤ On 24.1 The most ⼩ Integers
Floor Floor(24.1) The result returned to 24 ⼩ On 24.1 The most ⼤ Integers
Power Power(2,3) The result returned to “8” Calculation 2 Of 3 Time ⽅
Round Round(68.32,1) The result returned to 68.30 return ⼀ A digital , House ⼊ To the specified ⻓ Degree or accuracy
Sign Sign(123) The result returned to 1 Returns the symbol of a numeric value , Positive and negative zeros are returned respectively 1,
-1, 0
Sqrt Sqrt(16) The result returned to “4” Kaiping ⽅
Convert convert(1234,char(4))
The result returned to ”1234”
Data type conversion function , take 1234 Numeric type to
Replace with char type
Length length(‘ Come on China ’) The result returned to 12 Returns the number of bytes of any data type
ifnull(expr,value) select ifnull(city,‘ Unknown ’) from studentInfo If the value of the expression ⾮ empty , Returns the
value , Otherwise return to value
select user,host from mysql.user Returns the name of the computer and returns the current ⽤ The name of the computer on which the user logs in
SELECT Current_User Returns the current ⽤ The login name of the user returns the current ⽤ Household
2、SQL actual combat
-- function ——js function java The methods are very similar , There are receiving parameters and return values , A tool for writing is used to make fixed
Content
1
2 -- Intercepting string Determine whether it is null —— Functions are tools that come with the database itself
34 -- The function uses the format :
5 -- Writing directly is actually a demonstration. Just get the value directly
6 select CONCAT('a','b','c') as Name 1;
7 -- Source table , Operate on the column value of each row and return
8 select CONCAT(studentid,'_',studentname) from studentinfo
9 where CONCAT(studentid,'_',studentname)='2011001002_ Ma Yu '
101 -- SUBSTRING(str,pos) The first target string The second is the location of the interception Location slave 1 Start
12 select SUBSTRING('abcdefg',2);
13 -- The first is the goal The second is the starting position The third length
14 select SUBSTRING('abcdeft',2,3);
15 -- SUBSTR(str,pos)
16 select substr('abcdeft',2,3);
17 -- Operation table : Check all people surnamed Zhang
18 select SUBSTR(studentname,1,1),a.* FROM studentinfo a
19 where SUBSTR(studentname,1,1)=' Horse '
201 -- Get system time
22 select now()
234 -- Date plus
25 -- Back to 4 Months
26 select DATE_ADD('2020-3-24',INTERVAL -4 month)
27 -- Year plus 2 year
28 select DATE_ADD('2020-3-24',INTERVAL 2 year)
29 -- Add 40 God
30 select DATE_ADD('2020-3-24',INTERVAL 40 day)
312 -- Determine whether it is null -- If there is a value, it shows , Not displayed as none
33 select IFNULL(Birthday,' nothing '),a.* from studentinfo a
345 -- Integer
36 -- Down to the whole
37 select floor(23.6666),floor(23.333)
38 -- Up to the whole
39 select ceil(23.6666),ceil(23.333)
40 -- rounding
41 select ROUND(23.6666,2),round(23.333,2)
边栏推荐
- 初识结构体
- Brief introduction to the principle of spectrometer I
- UE5 GAS 学习笔记 1.8 游戏特效(GameplayCue)
- Zen project management software is an indispensable tool for agile development teams
- PyQt5快速开发与实战 5.3 多线程
- Modifier modifier modifier of solidity _;
- MYSQL入门与进阶(六)
- MySQL index usage and optimization
- NDK series (5): from introduction to practice, JNI explodes the liver and explains everything in detail!
- 记录自己在厦门两年来的面试经历--完结篇
猜你喜欢
随机推荐
NPM cannot recognize the "NPM" item as the name of a cmdlet, function, script file, or runnable program. Please check the spelling of the name. If the path is included, make sure the path is correct,
Ue5 gas learning notes 1.6 skills gameplay ability
UE5 GAS 学习笔记0.1 案例预览
Ue5 gas learning notes 1.7 task ability tasks
Go concurrency one
How does Xiaobai learn software testing with zero foundation?
Zen project management software is an indispensable tool for agile development teams
.net swagger
NDK series (5): from introduction to practice, JNI explodes the liver and explains everything in detail!
Live broadcast starrocks technology insider: low base global dictionary optimization
实验楼----PHP大法
Look at Devops construction from SRE
Ue5 gas learning notes 1.3 attribute
MYSQL入门与进阶(四)
Tcp/ip detailed diagram
LVS手册
Ue5 gas learning notes 1.5 gameplay effects game effects
Bubble sorting and Related videos
GIS数据漫谈(六)— 投影坐标系统
UE5 GAS 学习笔记 1.1能力系统组件Ability System Component









