1. 程式人生 > >Mysql 函數

Mysql 函數

文件 def 字符串 -- mea ubi 特殊字符 範圍 bsp

%:匹配零個及多個任意字符; _:與任意單字符匹配; []:匹配一個範圍; [^]:排除一個範圍
Symbol Meaning
like ‘5[%]‘ 5%
like ‘[_]n‘ _n
like ‘[a-cdf]‘ a, b, c, d, or f
like ‘[-acdf]‘ -, a, c, d, or f
like ‘[[]‘ [
like ‘]‘ ]
like ‘abc[_]d%‘ abc_d and abc_de
like ‘abc[def]‘ abcd, abce, and abcf
like ‘[^1-9]‘ 0
like ‘[^1-9b-z]‘ 0, a
對於字符串中出現的特殊字符:‘%‘,‘[‘,‘[]‘, ‘_‘ 可以使用 ‘[]‘ 把它們包含起來,這樣在匹配模式(pattern)中,它們就被當作普通字符對待了。
查詢
select * from (文件名) where (條件 xxx=‘xxx‘);
and :
=
!=
<,>,<>
like


select count(1) from anyun_tbl; (查詢總條數)
+----------+
| count(1) |
+----------+
| 3 |
+----------+
select count(1) as ‘number‘ from anyun_tbl where anyun_name = ‘上海‘;
+--------+
| number |
+--------+
| 1 |
+--------+

select count(1) as ‘number‘,anyun_name from anyun_tbl where anyun_name = ‘北京‘;
+--------+------------+
| number | anyun_name |
+--------+------------+
| 1 | NULL |
+--------+------------+


字符串拼接
select concat(‘1‘,‘2‘);
+-----------------+
| concat(‘1‘,‘2‘) |
+-----------------+
| 12 |
+-----------------+

select concat(anyun_id,‘-‘,anyun_name) from anyun_tbl;
+---------------------------------+
| concat(anyun_id,‘-‘,anyun_name) |
+---------------------------------+
| 1-shanghai |
| 2-beijing |
| 3-hubie |
+---------------------------------+


Mysql 函數