MySQL学习笔记

原创 2016年08月31日 08:49:57

45. MySQL运算符的使用

(1)算术运算符

①加减乘数

<span style="font-size:18px;">SELECT 1+2,3*7,1/3,23-88;</span>


②特殊的用法

<span style="font-size:18px;">SELECT 1/3MAIZI;</span>


②特殊的用法

<span style="font-size:18px;">SELECT 3/0;</span>
<pre name="code" class="sql"><span style="font-size:18px;">SELECT 3 DIV 0;</span>
<pre name="code" class="sql"><span style="font-size:18px;">SELECT 3%0;</span>
<span style="font-size:18px;">SELECT 3 MOD 0;</span>



+------+

| 3/0  |

+------+

| NULL |

+------+


(2)比较运算符

①等于

<span style="font-size:18px;">SELECT 1=1,1='1',1=2;</span>
<span style="font-size:18px;">--真为1,假为0</span>
<span style="font-size:18px;">SELECT username,username='king' FROM student;</span>
<p class="p1"><span class="s1"><span style="font-size:18px;">+------------+-----------------+</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">| username   | username='king' |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">+------------+-----------------+</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">| wanweiwei1 |               0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">| wanweiwei2 |               0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">| wanweiwei3 |               0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">| wanweiwei4 |               0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">| wanweiwei5 |               0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">| wanweiwei6 |               0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">| wanweiwei7 |               0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">+------------+-----------------+</span></span></p><span style="font-size: 18px;">
</span>


②不等于 <> != 比较数字,字符串


③null的比较,sex<=>null


④>=, <=

<span style="font-size:18px;">mysql> SELECT id,username,score,score>=70 from student;
+----+------------+-------+-----------+
| id | username   | score | score>=70 |
+----+------------+-------+-----------+
|  1 | wanweiwei1 |    88 |         1 |
|  2 | wanweiwei2 |    13 |         0 |
|  3 | wanweiwei3 |    77 |         1 |
|  4 | wanweiwei4 |    66 |         0 |
|  5 | wanweiwei5 |    55 |         0 |
|  6 | wanweiwei6 |    99 |         1 |
|  7 | wanweiwei7 |   100 |         1 |
+----+------------+-------+-----------+</span>

⑤IS NULL, IS NOT NULL


⑥BETWEEN AND

⑦IN, NOT IN

⑧LIKE,NOT LIKE
<span style="font-size:18px;">SELECT 's' LIKE '_';</span>
<span style="font-size:18px;">SELECT id,username,username LIKE '_____' FROM cms_user;</span>
<p class="p1"><span class="s1"><span style="font-size:18px;">+----+------------+-----------------------+</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">| id | username   | username LIKE '_____' |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">+----+------------+-----------------------+</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">|  8 | blek       |                     0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">| 11 | john       |                     0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">|  7 | king       |                     0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">| 10 | lily       |                     0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">| 14 | lll        |                     0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">|  4 | long       |                     0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">| 13 | Mao Zedong |                     0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">|  6 | queen      |                     1 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">|  5 | ring       |                     0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">|  9 | rose       |                     0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">| 12 | 万伟伟     |                     0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">|  1 | 张三       |                     0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">|  2 | 张三丰     |                     0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">|  3 | 章子怡     |                     0 |</span></span></p><p class="p1"><span class="s1"><span style="font-size:18px;">+----+------------+-----------------------+</span></span></p>

⑨正则REGEXP
^表示开头,$表示结尾,
<span style="font-size:18px;">SELECT id,username,username REGEXP '^b' FROM cms_user;
</span>


(3)逻辑运算符

①带NULL的时候要注意

SELECT 1&&1,2&&0,2&&NULL,1||1,1||0,1||NULL,0||NULL;

+------+------+---------+------+------+---------+---------+
| 1&&1 | 2&&0 | 2&&NULL | 1||1 | 1||0 | 1||NULL | 0||NULL |
+------+------+---------+------+------+---------+---------+
|    1 |    0 |    NULL |    1 |    1 |       1 |    NULL |
+------+------+---------+------+------+---------+---------+

②取反!


③抑或 XOR


(4)运算符的优先级







版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

mysql 学习笔记

  • 2015-08-08 15:40
  • 360KB
  • 下载

MySQL学习笔记 ADY

  • 2014-06-26 11:35
  • 1.32MB
  • 下载

【学习笔记】 使用Maven+SSM框架 + MySQL写一个小案例

Maven+SSM+MySQL的简单案例

mysql学习笔记

  • 2012-08-02 17:20
  • 16KB
  • 下载

mysql5 学习笔记

  • 2012-03-08 08:08
  • 453KB
  • 下载

springboot学习笔记(二):基于MySql数据库的JDBC操作

1 , 连接数据库SpringBoot的Web应用中,基于MySql数据库的JDBC操作 JDBC 连接数据库主要配置 1 , 属性配置文件(application.properties)spring...

MySQL学习笔记3

  • 2017-07-13 01:02
  • 7.21MB
  • 下载

MySql学习笔记

  • 2011-12-13 16:29
  • 46KB
  • 下载

MySQL学习笔记—视图

MySQL学习笔记—视图视图是查看基础表数据的一种方式,其作用有  - 简化开发难度,可以运用视图执行多表操作   - 数据安全,开发人员不能直接对表操作,也不能进行删除,修改操作   - 数据重...

MySQL5.5学习笔记

  • 2015-10-21 17:33
  • 10KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)