日期:2011-01-25 22:43:00 来源:本站整理
用你想不到的MySQL运算符得到更大都据对比功效[MySQL防范]
本文“用你想不到的MySQL运算符得到更大都据对比功效[MySQL防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
假如你在近来举行过SELECT或UPDATE查询,那么你极大概用到过一个大概多个MySQL的对比运算符来限制查询的输出后果.对比是大大都SELECT查询不可分割的一部份,而MySQL为这一功效供应了很多函数;按照近来一次统计,它有超越20个这样的运算符和函数,从闻名的=和LIKE到越发难懂的NOT IN和STRCMP(). 1VY4K4|}S
gM= sL
本文把重点放在一些不太常见的MySQL数据对比函数和运算符上,谈论它们可以被若何应用在利用程序里对比表格字段里的字符串、数字和日期/时间大概用户供应的值. 2X {r{C
Jlt0N)5
BETWEEN ?e6|E.S2
cZ1%MK(c:
BETWEEN运算符是测试在某个范围内能否存在一个数值大概日期值的有效方法.这个运算符承受两个参数——最大值和最小值,并测试所供应的值能否在这两个值的范围之内.假如在这个范围之内,运算符就返回一个布尔值——真;不然,它就返回一个伪值.下面就是一个例子: LO{e%I&{;
vnv4|^ZNnQ
mysql> SELECT 2350 BETWEEN 100 AND 10000; :k4RPM7oS
+----------------------------+ L%T6ai1~
| 2350 BETWEEN 100 AND 10000 | 1H-~cV1c
+----------------------------+ QvmGwFO
| 1 | M#FhJvE4QJ
+----------------------------+ m5HY$9d
1 row in set (0.18 sec) !vBxXnY;
1z2%TZ='
下面两个例子用到了日期值: YXV 9Mi
5 ""&3
mysql> SELECT 20060405 BETWEEN 20060101 AND 20070101; fUue'U|5
+----------------------------------------+ :bSK WoQ{
| 20060405 BETWEEN 20060101 AND 20070101 | MVW]|Lv
+----------------------------------------+ 9`ia<~X4N
| 1 | i|W/(Q@9
+----------------------------------------+ >nr?U% " c
1 row in set (0.00 sec) xqTpW.1
^n[lQh
mysql> SELECT 20060405 BETWEEN 20060101 AND 20060401; "7mG+Ak
+----------------------------------------+ p$@ch4i
| 20060405 BETWEEN 20060101 AND 20060401 | -c-[K6a_
+----------------------------------------+ 8hM?i_}IQ
| 0 | |_O7sBx&
+----------------------------------------+ [)51f+oC8
1 row in set (0.00 sec) ?N1LMD1qp$
7l E&D
GREATEST和LEAST *p@1}e}&A
$(J >m:j
GREATEST和LEAST运算符为判断一组数字大概时间值中最大和最小值供应了一个便捷的途径.你一看名字就知道这两个运算符的作用——下面是一个对一组日期利用GREATEST运算符的例子: +q+cyX
9zw7;jz^ +
mysql> SELECT GREATEST(20000601, 20000529, 20000604); GC)XtG5b
+----------------------------------------+ =[|IEZYq
| GREATEST(20000601, 20000529, 20000604) | :Op\PrM1f
+----------------------------------------+ |vLQb*Q
| 20000604 | BE^"n}75
+----------------------------------------+ 5|GFPd\Pg
1 row in set (0.00 sec) Xcq4XGwnj
@M2o A.7
而下面是一个对一组数值利用LEAST运算符的例子: ]Hm^_f+
oewSeplb
mysql> SELECT LEAST(100, 200, 50, -6, -73, 1000); =PF:Xj!
+------------------------------------+ Y/"C aKm
| LEAST(100, 200, 50, -6, -73, 1000) | 0Ad=,0z
+------------------------------------+ QVV?[c8K
| -73 | ZKivc xF3L
+------------------------------------+ "d KO`1
1 row in set (0.03 sec)
gM= sL
本文把重点放在一些不太常见的MySQL数据对比函数和运算符上,谈论它们可以被若何应用在利用程序里对比表格字段里的字符串、数字和日期/时间大概用户供应的值. 2X {r{C
Jlt0N)5
BETWEEN ?e6|E.S2
cZ1%MK(c:
BETWEEN运算符是测试在某个范围内能否存在一个数值大概日期值的有效方法.这个运算符承受两个参数——最大值和最小值,并测试所供应的值能否在这两个值的范围之内.假如在这个范围之内,运算符就返回一个布尔值——真;不然,它就返回一个伪值.下面就是一个例子: LO{e%I&{;
vnv4|^ZNnQ
mysql> SELECT 2350 BETWEEN 100 AND 10000; :k4RPM7oS
+----------------------------+ L%T6ai1~
| 2350 BETWEEN 100 AND 10000 | 1H-~cV1c
+----------------------------+ QvmGwFO
| 1 | M#FhJvE4QJ
+----------------------------+ m5HY$9d
1 row in set (0.18 sec) !vBxXnY;
1z2%TZ='
下面两个例子用到了日期值: YXV 9Mi
5 ""&3
mysql> SELECT 20060405 BETWEEN 20060101 AND 20070101; fUue'U|5
+----------------------------------------+ :bSK WoQ{
| 20060405 BETWEEN 20060101 AND 20070101 | MVW]|Lv
+----------------------------------------+ 9`ia<~X4N
| 1 | i|W/(Q@9
+----------------------------------------+ >nr?U% " c
1 row in set (0.00 sec) xqTpW.1
^n[lQh
mysql> SELECT 20060405 BETWEEN 20060101 AND 20060401; "7mG+Ak
+----------------------------------------+ p$@ch4i
| 20060405 BETWEEN 20060101 AND 20060401 | -c-[K6a_
+----------------------------------------+ 8hM?i_}IQ
| 0 | |_O7sBx&
+----------------------------------------+ [)51f+oC8
1 row in set (0.00 sec) ?N1LMD1qp$
7l E&D
GREATEST和LEAST *p@1}e}&A
$(J >m:j
GREATEST和LEAST运算符为判断一组数字大概时间值中最大和最小值供应了一个便捷的途径.你一看名字就知道这两个运算符的作用——下面是一个对一组日期利用GREATEST运算符的例子: +q+cyX
9zw7;jz^ +
mysql> SELECT GREATEST(20000601, 20000529, 20000604); GC)XtG5b
+----------------------------------------+ =[|IEZYq
| GREATEST(20000601, 20000529, 20000604) | :Op\PrM1f
+----------------------------------------+ |vLQb*Q
| 20000604 | BE^"n}75
+----------------------------------------+ 5|GFPd\Pg
1 row in set (0.00 sec) Xcq4XGwnj
@M2o A.7
而下面是一个对一组数值利用LEAST运算符的例子: ]Hm^_f+
oewSeplb
mysql> SELECT LEAST(100, 200, 50, -6, -73, 1000); =PF:Xj!
+------------------------------------+ Y/"C aKm
| LEAST(100, 200, 50, -6, -73, 1000) | 0Ad=,0z
+------------------------------------+ QVV?[c8K
| -73 | ZKivc xF3L
+------------------------------------+ "d KO`1
1 row in set (0.03 sec)
假如你在近来举行过SELECT或UPDATE查询,那么你极大概用到过一个大概多个MySQL的对比运算符来限制查询的输出后果.对比是大大都SELECT查询不可分割的一部份,而MySQL为这一功效供应了很多函数;按照近来一次统计,它有超越20个这样的运算符和函数,从闻名的=和LIKE到越发难懂的NOT IN和STRCMP(). w< wYS 0/
`[9ieXPB-_
本文把重点放在一些不太常见的MySQL数据对比函数和运算符上,谈论它们可以被若何应用在利用程序里对比表格字段里的字符串、数字和日期/时间大概用户供应的值. cH5u;zK4`
xi2 "w r9
BETWEEN `'IUKa
}MmNDq
BETWEEN运算符是测试在某个范围内能否存在一个数值大概日期值的有效方法.这个运算符承受两个参数——最大值和最小值,并测试所供应的值能否在这两个值的范围之内.假如在这个范围之内,运算符就返回一个布尔值——真;不然,它就返回一个伪值.下面就是一个例子: TC^`&"
Nlw6 G_bLF
mysql> SELECT 2350 BETWEEN 100 AND 10000; ):zC9;:
+----------------------------+ LxyZm
| 2350 BETWEEN 100 AND 10000 | v"6*y2a N
+----------------------------+ \91$M@
| 1 | V5+]n
+----------------------------+ LSt<S*[
1 row in set (0.18 sec) ;R>|*y
z|US~Tl
下面两个例子用到了日期值: *75TVy?D
]rrpq%z
mysql> SELECT 20060405 BETWEEN 20060101 AND 20070101; NC>E(z
+----------------------------------------+ 5+BUJB4_pM
| 20060405 BETWEEN 20060101 AND 20070101 | d1^1 cr
+----------------------------------------+ iD]|sX%^0
| 1 | 3+=E{_0C
+----------------------------------------+ }TDp('^
1 row in set (0.00 sec) F{ewZsjd=
NVXTQ&|Xx
mysql> SELECT 20060405 BETWEEN 20060101 AND 20060401; {.'+W
+----------------------------------------+ ]}O0 nriE
| 20060405 BETWEEN 20060101 AND 20060401 | EXRP\Fh
+----------------------------------------+ pznE<
| 0 | .6&l`O/#
+----------------------------------------+ Iv.i5Y5
1 row in set (0.00 sec) Q%2WeRU//
3_HF8
GREATEST和LEAST e!}S7*RyN-
($.zdoUr&v
GREATEST和LEAST运算符为判断一组数字大概时间值中最大和最小值供应了一个便捷的途径.你一看名字就知道这两个运算符的作用——下面是一个对一组日期利用GREATEST运算符的例子: >oh!wq[+
`G~ofP8
mysql> SELECT GREATEST(20000601, 20000529, 20000604); F6$ l {bm
+----------------------------------------+ H* 1o5vg
| GREATEST(20000601, 20000529, 20000604) | }YXH:8I
+----------------------------------------+ .62Dx{
| 20000604 | t!%i/:J'[
+----------------------------------------+ u)12rx
1 row in set (0.00 sec) h ,NJ.mK
MFVN%.E r
而下面是一个对一组数值利用LEAST运算符的例子: Q,rcyIM
o1S4#?Sy
mysql> SELECT LEAST(100, 200, 50, -6, -73, 1000); S 9)TvQ
+------------------------------------+ 5Nhr|@b0
| LEAST(100, 200, 50, -6, -73, 1000) | SNi9WIjP`
+------------------------------------+ rIo qO# 3
| -73 | #:z &&)Y&C
+------------------------------------+ ))%8e1rB
1 row in set (0.03 sec)
以上是“用你想不到的MySQL运算符得到更大都据对比功效[MySQL防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:`[9ieXPB-_
本文把重点放在一些不太常见的MySQL数据对比函数和运算符上,谈论它们可以被若何应用在利用程序里对比表格字段里的字符串、数字和日期/时间大概用户供应的值. cH5u;zK4`
xi2 "w r9
BETWEEN `'IUKa
}MmNDq
BETWEEN运算符是测试在某个范围内能否存在一个数值大概日期值的有效方法.这个运算符承受两个参数——最大值和最小值,并测试所供应的值能否在这两个值的范围之内.假如在这个范围之内,运算符就返回一个布尔值——真;不然,它就返回一个伪值.下面就是一个例子: TC^`&"
Nlw6 G_bLF
mysql> SELECT 2350 BETWEEN 100 AND 10000; ):zC9;:
+----------------------------+ LxyZm
| 2350 BETWEEN 100 AND 10000 | v"6*y2a N
+----------------------------+ \91$M@
| 1 | V5+]n
+----------------------------+ LSt<S*[
1 row in set (0.18 sec) ;R>|*y
z|US~Tl
下面两个例子用到了日期值: *75TVy?D
]rrpq%z
mysql> SELECT 20060405 BETWEEN 20060101 AND 20070101; NC>E(z
+----------------------------------------+ 5+BUJB4_pM
| 20060405 BETWEEN 20060101 AND 20070101 | d1^1 cr
+----------------------------------------+ iD]|sX%^0
| 1 | 3+=E{_0C
+----------------------------------------+ }TDp('^
1 row in set (0.00 sec) F{ewZsjd=
NVXTQ&|Xx
mysql> SELECT 20060405 BETWEEN 20060101 AND 20060401; {.'+W
+----------------------------------------+ ]}O0 nriE
| 20060405 BETWEEN 20060101 AND 20060401 | EXRP\Fh
+----------------------------------------+ pznE<
| 0 | .6&l`O/#
+----------------------------------------+ Iv.i5Y5
1 row in set (0.00 sec) Q%2WeRU//
3_HF8
GREATEST和LEAST e!}S7*RyN-
($.zdoUr&v
GREATEST和LEAST运算符为判断一组数字大概时间值中最大和最小值供应了一个便捷的途径.你一看名字就知道这两个运算符的作用——下面是一个对一组日期利用GREATEST运算符的例子: >oh!wq[+
`G~ofP8
mysql> SELECT GREATEST(20000601, 20000529, 20000604); F6$ l {bm
+----------------------------------------+ H* 1o5vg
| GREATEST(20000601, 20000529, 20000604) | }YXH:8I
+----------------------------------------+ .62Dx{
| 20000604 | t!%i/:J'[
+----------------------------------------+ u)12rx
1 row in set (0.00 sec) h ,NJ.mK
MFVN%.E r
而下面是一个对一组数值利用LEAST运算符的例子: Q,rcyIM
o1S4#?Sy
mysql> SELECT LEAST(100, 200, 50, -6, -73, 1000); S 9)TvQ
+------------------------------------+ 5Nhr|@b0
| LEAST(100, 200, 50, -6, -73, 1000) | SNi9WIjP`
+------------------------------------+ rIo qO# 3
| -73 | #:z &&)Y&C
+------------------------------------+ ))%8e1rB
1 row in set (0.03 sec)
本文地址: | 与您的QQ/BBS好友分享! |
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论