concat(str1, str2,...)
concat(str1, seperator,str2,seperator,...)
concat_ws(separator, str1, str2, ...)
select concat("123","456","789") "concat",concat_ws("-","123","456") "concatws"
-- 查询结果
|concat |concatws |
+----------+---------+
|123456789 |123-456 |
+----------+---------+
GROUP_CONCAT([DISTINCT] expr [,expr ...] [order by 排序字段 asc/desc ] [separator '分隔符'])
select
deptno,
GROUP_CONCAT(distinct EMPNO order by EMPNO desc separator ';') "group-concat"
from
emp
group by
deptno;
-- 运行结果
|deptno|group-concat |
+------+-----------------------------+
| 10|7934;7839;7782 |
| 20|7902;7876;7788;7566;7369 |
| 30|7900;7844;7698;7654;7521;7499|
| 40|8000 |
length("String")
char_length("String")
select length("字符串有多长") "len",char_length("字符串有多长") "c-l"
-- 查询结果
|len|c-l|
+---+---+
| 18| 6|
substring(str,a,b):提取字段中的一段,从字符串str的第a位开始提取,提取b个字符
left(str,n):提取字符串最左边的n个字符
right(str,n):提取字符串最右边的n个字符(该例未用到)
select substring("字符串有多长",4,3) "len"
-- 结果
len |
------+
有多长|
select left("字符串有多长",3) "left"
-- 结果
left |
------+
字符串 |
select right("字符串有多长",3) "right"
-- 结果
right |
-------+
有多长 |
SELECT REPLACE (Region_Name, 'ast', 'astern') FROM Geography;
select replace("字符串有多长","字符串","String") "replace"
-- 结果
replace|
------------+
String有多长 |
select ifnull(comm,1) from emp;
-- ------ 结果
|ifnull(comm,11)|
+---------------+
| 1400.0|
| 0.0|
| 11.0|
| 11.0|
select coalesce(comm,1) from emp;
-- -------结果
|coalesce(comm,1)|
+----------------+
| 1400.0|
| 0.0|
| 1.0|
| 1.0|
select coalesce(null,null,9,1,0)
-- --------------------------
|coalesce(null,null,9,1,0)|
+-------------------------+
| 9|
SELECT STRCMP("SQL Tutorial", "SQL Tutorial");
select strcmp(1,0),strcmp(0,1),strcmp(1,1)
-- 结果------------------------
strcmp(1,0)|strcmp(0,1)|strcmp(1,1)|
-----------+-----------+-----------+
1| -1| 0|
select lower("ARAY"),upper("all")
-- 结果------------------
lower("ARAY")|upper("all")|
-------------+------------+
aray |ALL |
CONCAT(UPPER(left(ename,1)),LOWER(RIGHT(ename,length(t_ename)-1))) as name
select
CONCAT(UPPER(left(ename, 1)), LOWER(right(ename, length(ename)-1))) as name
from
emp e
-- jieguo --------------------
|name |
+------+
|Smith |
|Allen |
|Ward |
|Jones |
|Martin|