1. Character Function1. Case control function ① SELECT UPPER('Hello'); ② SELECT LOWER('Hello'); 2. Character control function ① SELECT LENGTH('Chloroplasts do not forget to breathe aaaa'); ② SELECT CONCAT('Hello','世界') AS result; ③ #Start intercepting from the 4th one, intercept all the ones after that SELECT SUBSTR('I believe in light',4); #Start from the first one and intercept 3 SELECT SUBSTR('I believe in light',1,3); ④ SELECT INSTR('Chinese national football team will play away against Saudi Arabia on October 13','Saudi Arabia') AS result; ⑤ SELECT TRIM('a' FROM 'aaaaachloroplastaaaaa') AS result; #Remove spaces SELECT TRIM(' Chloroplast aa ') AS result; ⑥ SELECT LPAD('chloroplast',9,'a') AS result; ⑦ SELECT REPLACE('a叶aaa chloroplastaaaa','a','B') AS result; 2. Mathematical Functions ① #One decimal place is retained by defaultSELECT ROUND(1.62) AS result; #Keep two decimal placesSELECT ROUND(1.627,2) AS result; ② SELECT CEIL(1.002) AS result; ③ SELECT FLOOR(1.002) AS result; ④ SELECT TRUNCATE(1.699,1) AS result; ⑤ SELECT MOD(10,-3) AS result; 3. Date functions①NOW(): Returns the current system date and time SELECT NOW(); ②CURDATE(): Returns the current system date, excluding time SELECT CURDATE(); ③CURTIME(): Returns the current system time, excluding the date SELECT CURTIME(); ⑦ SELECT YEAR(NOW()); SELECT YEAR('2021-09-30') AS result; ⑧ SELECT MONTH('2021-09-30') AS result; SELECT MONTHNAME('2021-09-30') AS result; Days, hours, minutes, and seconds can all be listed above ⑨ #It is equivalent to parsing: the two parameter formats must match SELECT STR_TO_DATE('9-30 2021','%m-%d %Y') AS result; ⑩ #It is equivalent to formatting SELECT DATE_FORMAT(NOW(),'%Y year %m month %d day') AS result; 4. Other functions#Check the version SELECT VERSION(); #View the database SELECT DATABASE(); #View userSELECT USER(); 5. Process Control Function ① SELECT IF(10>5,'big','small') AS result; ② CASE WHEN constant to be judged 1 THEN statement 1; or the value to be displayed 1 ... ELSE statement; or the value to be displayed END Example #The example is the value to be displayed, without ';' SELECT `last_name`,`salary`,`department_id`, CASE `department_id` WHEN 100 THEN `salary`*(1+0.8) WHEN 90 THEN `salary`*(1+0.6) WHEN 80 THEN `salary`*(1+0.4) WHEN 70 THEN `salary`*(1+0.2) ELSE `salary` END AS finalsalaryFROM employees; ③ Use of CASE WHEN condition 1 THEN SELECT statement 1; or the value to be displayed 1 ... ELSE statement; or the value to be displayed END Example #The example is the value to be displayed, without ';' SELECT `last_name`,`salary`, CASE WHEN `salary`>20000 THEN 'A level' WHEN `salary`>15000 THEN 'B level' WHEN `salary`>10000 THEN 'C level' ELSE 'D level' END AS level FROM employees; This concludes this article on MySQL's in-depth explanation of single-row functions and character math date process control. For more relevant MySQL single-row function content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
>>: Conditional comment style writing method and sample code
Author: Guan Changlong is a DBA in the Delivery S...
First time writing. Allow me to introduce myself....
Dig Introduction: Dig is a tool that queries DNS ...
The main differences are as follows: 1. MySQL use...
I encountered a problem when I turned on my lapto...
Overview Operations on any one database are autom...
I've been researching some things about linke...
<> Operator Function: Indicates not equal t...
This article example shares the specific code of ...
Table of contents 1. Default values for functio...
This article shares the specific code of Vue recu...
tomcat official website tomcat is equivalent to a...
Preface Golang provides the database/sql package ...
Grouping and linking in MYSQL are the two most co...
1. Download jdk download address我下載的是jdk-8u221-li...