In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail the examples of the use of operators in mysql. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Example: create a data table tmp15 that contains fields of type varchar note and field price of type int.
Use operators to operate on different fields in the table tmp15.
Use logical operators to logically manipulate the data.
Use the bit operator to perform bit operations on the data.
First create the tmp15 table and insert a record with a note value of "Thisisgood" and a price value of 50 SQL statements as follows:
Mysql > create table tmp15-> (- > note varchar,-> 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) perform arithmetic on the integer numeric field price in table tmp15. The SQL statement is as follows:
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 | 25.0000 | 2 | +-+ -+-+ 1 row in set (0.00 sec)
(2) compare the integer numeric field price in table tmp15. The SQL statement is as follows:
Mysql > select price,-> price > 10,-> price price! = 10,-> price = 10,-> price10,-> price10-> from tmp15 +-+ | price | price > 10 | price 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 Magazine 30) | price in (10, 20, 50, 50, 35) | +-+ | 50 | 1 | 70 | 1 | +-+ 1 row in set (0.00 sec)
(4) compare the string numeric field note in tmp15, determine whether the note field in table tmp15 is empty, use LIKE to determine whether it begins with the letter "t", use regexp to determine whether it ends with the letter "y", and determine whether it contains the letter "g" or "m". The SQL statement is as follows:
Mysql > select note,-> note is null,-> note like't% shipping,-> note regexp'$yearly,-> 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) logically operate the price field value with null and 0. The SQL statement is as follows:
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) perform bitwise and, bitwise or bitwise operations on price field values with 2 and 4, and bitwise operations on price. The SQL statement is as follows:
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) shift the value of the price field to the left and right, respectively. The SQL statement is as follows:
Mysql > select price,-> price > 2-> from tmp15 +-+ | price | price2 | +-+ | 50 | 200 | 12 | +-+ 1 row in set (0.00 sec) about "mysql" That's all for the article "examples of the use of operators in" Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.