在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

mysql中运算符的使用示例

107次阅读
没有评论

共计 4374 个字符,预计需要花费 11 分钟才能阅读完成。

自动写代码机器人,免费开通

这篇文章将为大家详细讲解有关 mysql 中运算符的使用示例,丸趣 TV 小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

案例:创建数据表 tmp15,其中包含 varchar 类型的字段 note 和 int 类型的字段 price。

使用运算符对表 tmp15 中不同的字段进行运算。

使用逻辑操作符对数据进行逻辑操作。

使用位操作符对数据进行位操作。

首先创建 tmp15 表,插入一条记录,note 值为 Thisisgood,price 值为 50,SQL 语句如下:

mysql  create table tmp15 -  ( -  note varchar(100),
 -  price int
 -  );Query OK, 0 rows affected (0.13 sec)mysql  into tmp15 values
 -  (
 -   Thisisgood ,50
 -  );
 mysql  insert into tmp15 values
 -  (Thisisgood ,50);Query OK, 1 row affected (0.06 sec)

(1)对表 tmp15 中的整型数值字段 price 进行算数运算,SQL 语句如下:

mysql  select price,
 -  price + 10,
 -  price - 10,
 -  price * 2,
 -  price / 2,
 -  price % 3
 -  from tmp15;+-------+------------+------------+-----------+-----------+-----------+| price | price + 10 | price - 10 | price * 2 | price / 2 | price % 3 |+-------+------------+------------+-----------+-----------+-----------+| 50 | 60 | 40 | 100 | 25.0000 | 2 |+-------+------------+------------+-----------+-----------+-----------+1 row in set (0.00 sec)

(2)对表 tmp15 中的整型数值字段 price 进行比较运算,SQL 语句如下:

mysql  select price,
 -  price 10,
 -  price 10,
 -  price != 10,
 -  price = 10,
 -  price = 10,
 -  price 10
 -  from tmp15;+-------+----------+----------+-------------+------------+------------+-----------+| price | price 10 | price 10 | price != 10 | price = 10 | price = 10 | price 10 |+-------+----------+----------+-------------+------------+------------+-----------+| 50 | 1 | 0 | 1 | 0 | 0 | 1 |+-------+----------+----------+-------------+------------+------------+-----------+1 row in set (0.00 sec)

(3)判断 price 值是否落在 30—80 区间、返回 70、30 相比最大的值、判断 price 是否为 in 列表 (10、20、50、35) 中的某个值,SQL 语句如下:

mysql  select price,
 -  price between 30 and 80,
 -  greatest(price,70,30),
 -  price in(10,20,50,35)
 -  from tmp15;+-------+-------------------------+-----------------------+-----------------------+| price | price between 30 and 80 | greatest(price,70,30) | price in(10,20,50,35) |+-------+-------------------------+-----------------------+-----------------------+| 50 | 1 | 70 | 1 |+-------+-------------------------+-----------------------+-----------------------+1 row in set (0.00 sec)

(4)对 tmp15 中的字符串数值字段 note 进行比较运算,判断表 tmp15 中 note 字段是否为空、使用 LIKE 判断是否以字母 t 开头、使用 regexp 判断是否以字母“y”结尾、判断是否包含字母“g”或者“m”,SQL 语句如下:

mysql  select note,
 -  note is null,
 -  note like  t% ,
 -  note regexp  $y ,
 -  note regexp  [gm] 
 -  from tmp15;+------------+--------------+----------------+------------------+--------------------+| note | note is null | note like  t%  | note regexp  $y  | note regexp  [gm]  |+------------+--------------+----------------+------------------+--------------------+| Thisisgood | 0 | 1 | 0 | 1 |+------------+--------------+----------------+------------------+--------------------+1 row in set (0.05 sec)

(5)将 price 字段值与 null、0 进行逻辑运算,SQL 语句如下:

mysql  select price,
 -  price   1,
 -  price   null,
 -  price || 0,
 -  price and 0,
 -  0 and null,
 -  price or null
 -  from tmp15;+-------+------------+---------------+------------+-------------+------------+---------------+| price | price   1 | price   null | price || 0 | price and 0 | 0 and null | price or null |+-------+------------+---------------+------------+-------------+------------+---------------+| 50 | 1 | NULL | 1 | 0 | 0 | 1 |+-------+------------+---------------+------------+-------------+------------+---------------+1 row in set (0.00 sec)mysql  select price,
 -  !price,
 -  not null,
 -  price xor 3,
 -  0 xor null,
 -  price xor 0
 -  from tmp15;+-------+--------+----------+-------------+------------+-------------+| price | !price | not null | price xor 3 | 0 xor null | price xor 0 |+-------+--------+----------+-------------+------------+-------------+| 50 | 0 | NULL | 0 | NULL | 1 |+-------+--------+----------+-------------+------------+-------------+1 row in set (0.00 sec)

(6)将 price 字段值与 2、4 进行按位与、按位或 操作,并对 price 进行按位操作,SQL 语句如下:

mysql  select price,
 -  price   2,
 -  price | 4,
 -  ~price from tmp15;+-------+-----------+-----------+----------------------+| price | price   2 | price | 4 | ~price |+-------+-----------+-----------+----------------------+| 50 | 2 | 54 | 18446744073709551565 |+-------+-----------+-----------+----------------------+1 row in set (0.00 sec)

(7)将 price 字段值分别额左移和右移两位,SQL 语句如下:

mysql  select price,
 -  price 2,
 -  price 2
 -  from tmp15;+-------+----------+----------+| price | price 2 | price 2 |+-------+----------+----------+| 50 | 200 | 12 |+-------+----------+----------+1 row in set (0.00 sec)

关于“mysql 中运算符的使用示例”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向 AI 问一下细节

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-12-04发表,共计4374字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 深夜影院在线视频观看 | 毛片网战| 女教师淫辱の教室在线 | 少妇伦子伦精品无吗 | 丰满少妇熟女高潮流白浆 | 国产线视频精品免费观看视频 | 成人看的一级毛片 | 日本猛妇色xxxxx在线 | 国产精品视频成人 | 丰满的邻居hd高清伦理 | 欧美一级视频在线高清观看 | 日本牲交大片免费观看 | 俺也来俺也去俺也射 | 无码aⅴ在线观看 | 闲人吧综合免费888精品 | 黄网在线免费看 | 亚洲成人免费 | 黄色日本片 | 欧美一级在线观看播放 | 国模思思| 欧美最大成人毛片视频网站 | 色欲麻豆国产福利精品 | 思思久久96热在精品不卡 | 性久久久久久久久久 | 欧亚毛片| 亚洲欧美成人一区二区在线电影 | 亚洲精品777 | 久久天天操 | 国产成人无码免费网站 | 扒开双腿猛进入喷水免费视频 | 国产激情电影综合在线看 | 天堂sv在线最新版在线 | 欧美综合视频 | 色婷婷国产 | 国产思思99re99在线观看 | 麻豆网站免费观看 | 国产成人精品视频免费大全 | 精品无码一区二区三区在线 | 偷拍视频一区在线观看 | 亚洲最大成人综合网720p | 精品少妇人妻av一区二区 |