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
This article lists the most commonly used image c...
Table of contents 1. Introduce cases 2. View the ...
This article example shares the specific code of ...
Preface In many management and office systems, tr...
Easy installation of opencv2: conda install --cha...
Table of contents 1. What is front-end state mana...
I would like to share with you the graphic tutori...
<br />This tag is used to create a multi-lin...
Table of contents Method 1: Routing meta informat...
Table of contents Deploy nginx on server1 Deploy ...
When developing a mobile page recently, I encount...
Compared with vue2, vue3 has an additional concep...
Sometimes when requesting certain interfaces, you...
This article mainly introduces the example analys...
When I configured mysql, I set the default storag...