当前位置:网站首页>MySQL function
MySQL function
2022-06-30 01:04:00 【Hua Weiyun】
function
- String function
- Numerical function
- Date function
- Flow function
String function
Common functions :
| function | function |
|---|---|
| CONCAT(s1, s2, …, sn) | String splicing , take s1, s2, …, sn Concatenate into a string |
| LOWER(str) | Convert all strings to lowercase |
| UPPER(str) | Convert all strings to uppercase |
| LPAD(str, n, pad) | padding-left , Use string pad Yes str Fill the left side of the , achieve n String length |
| RPAD(str, n, pad) | Right fill , Use string pad Yes str Fill the right side of the , achieve n String length |
| TRIM(str) | Remove the spaces at the beginning and end of the string |
| SUBSTRING(str, start, len) | Return from string str from start It's from the position len A string of length |
Examples of use :
-- Splicing SELECT CONCAT('Hello', 'World');-- A lowercase letter SELECT LOWER('Hello');-- Capitalization SELECT UPPER('Hello');-- padding-left SELECT LPAD('01', 5, '-');-- Right fill SELECT RPAD('01', 5, '-');-- Remove the space SELECT TRIM(' Hello World ');-- section ( The starting index is 1)SELECT SUBSTRING('Hello World', 1, 5);Numerical function
Common function :
| function | function |
|---|---|
| CEIL(x) | Rounding up |
| FLOOR(x) | Rounding down |
| MOD(x, y) | return x/y The mold |
| RAND() | return 0~1 The random number in |
| ROUND(x, y) | Find parameters x Round the value of , Retain y Decimal place |
Date function
Common functions :
| function | function |
|---|---|
| CURDATE() | Return current date |
| CURTIME() | Return current time |
| NOW() | Returns the current date and time |
| YEAR(date) | Get specified date A year of |
| MONTH(date) | Get specified date Month of |
| DAY(date) | Get specified date Date |
| DATE_ADD(date, INTERVAL expr type) | Return a date / Time value plus a time interval expr Time value after |
| DATEDIFF(date1, date2) | Return to start time date1 And end time date2 Days between |
Example :
-- DATE_ADDSELECT DATE_ADD(NOW(), INTERVAL 70 YEAR);Flow function
Common functions :
| function | function |
|---|---|
| IF(value, t, f) | If value by true, Then return to t, Otherwise return to f |
| IFNULL(value1, value2) | If value1 Not empty , return value1, Otherwise return to value2 |
| CASE WHEN [ val1 ] THEN [ res1 ] … ELSE [ default ] END | If val1 by true, return res1,… Otherwise return to default The default value is |
| CASE [ expr ] WHEN [ val1 ] THEN [ res1 ] … ELSE [ default ] END | If expr The value is equal to the val1, return res1,… Otherwise return to default The default value is |
Example :
select name, (case when age > 30 then ' middle-aged ' else ' youth ' end)from employee;select name, (case workaddress when ' The Beijing municipal ' then ' first-tier cities ' when ' Shanghai ' then ' first-tier cities ' else ' Second-tier cities ' end) as ' Work address 'from employee;边栏推荐
- RubyMine开发工具,重构和意图操作
- 作文总写不好怎么办?猿辅导:家长要注意这几点
- [spark] basic Scala operations (continuous update)
- Too voluminous ~ eight part essay, the strongest king of interview!
- Exercise "product": self made colorful Prompt string display tool (for loop and if condition judgment)
- VIM editor common instructions
- [deep learning compilation] operator compilation IR conversion
- Cloud, IPv6 and all-optical network
- Netease cloud music beta music social app "mus" matches friends of the same frequency through music
- What if you can't write your composition well? Ape counseling: parents should pay attention to these points
猜你喜欢

Online text digit recognition list summation tool

赛芯电子冲刺科创板上市:拟募资6.23亿元,共有64项专利申请信息

Seata 與三大平臺攜手編程之夏,百萬獎金等你來拿

练习副“产品”:自制七彩提示字符串展示工具(for循环、if条件判断)

Netease cloud music beta music social app "mus" matches friends of the same frequency through music

SFDP super form development platform v6.0.4 was officially released

Seata and the three platforms are working together in the summer of programming. Millions of bonuses are waiting for you

81. search rotation sort array II

Clean, talk, bring children, and get rid of the label of "artificial mental retardation" for the sweeper

latex如何输入一个矩阵
随机推荐
外包干了三年,废的一踏糊涂...
[mrctf2020]ezpop-1 | PHP serialization
【深度学习编译】算子编译 IR 转换
我,33岁,字节跳动测试开发,揭开北京“测试岗”的真实收入
网易云音乐内测音乐社交 App“MUS”,通过音乐匹配同频朋友
About the case of SQL statements
[cloud native] kernel security in container scenario
Seata 与三大平台携手编程之夏,百万奖金等你来拿
优秀的测试/开发程序员与普通的程序员对比......
Programmers with a monthly salary of less than 30K must recite the interview stereotype. I will eat it first!
[three.js] Web3D first experience
赛芯电子冲刺科创板上市:拟募资6.23亿元,共有64项专利申请信息
How latex enters a matrix
传统微服务框架如何无缝过渡到服务网格 ASM
Time flies that year
在线SQL转CSV工具
numpy的索引和图片的索引一样吗?
81. 搜索旋转排序数组 II
阿洛觉得自己迷茫
【three.js】WEB3D初次体验