Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An Analysis of mysql data Operation

2025-03-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces mysql data operation analysis, the content of the article is carefully selected and edited by the author, mysql data operation analysis has a certain pertinence, for everyone's reference significance is still relatively great, the following with the author to understand the next topic content.

1. Purpose of the case

Create a data table, and operate on the data in the table, and master the use of various operators.

Create table tmp15, which contains fields of type VARCHAR note and field price of type INT, use operators to operate on different fields in table tmp15, use logical operators to logically manipulate data, and use bit operators to perform bit operations on data.

This case uses the data table tmp15, which is first created with the following SQL statement:

CREATE TABLE tmp15 (note VARCHAR, price INT)

Insert a record into the table with a note value of "Thisisgood" and a price value of 50 SQL statements as follows:

INSERT INTO tmp15 VALUES ("Thisisgood", 50)

two。 Case operation process

Perform an arithmetic operation on the integer numeric field price in table tmp15, as follows:

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 |

+-+ +

Compare the integer numeric field price in table tmp15. The process is as follows:

SELECT price, price > 10, price 10 | price SELECT price, price BETWEEN 30 AND 80, GREATEST (price, 70 AND 30), price IN (10,20,50 FROM tmp15)

+-- +

| | price | price BETWEEN 30 AND 80 | GREATEST (price, 70 AND 30) | price IN (10,20,50 focus 35) |

+-- +

| | 50 | 1 | 70 | 1 |

+-- +

Compare the string numeric field note in tmp15 to determine whether the note field in table tmp15 is empty; use LIKE to determine whether it starts 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 execution process is as follows:

Mysql > SELECT note, note IS NULL, note LIKE't% shipping, 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 | |

+-+

Perform a logical operation between the value of the price field and NULL,0 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 XOR NULL,price XOR NULL,price XOR not 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)

Bitwise and, bitwise or operate price field values with 2,4, and bitwise price as follows:

Mysql > SELECT price, price&2, price | 4, ~ price FROM tmp15

+-+

| | price | price&2 | price | 4 | ~ price |

+-+

| | 50 | 2 | 54 | 18446744073709551565 | |

+-+

Move the price field value by two digits to the left and right, respectively, as follows:

Mysql > SELECT price, price2 FROM tmp15

+-+

| | price | price 2 |

+-+

| | 50 | 200 | 12 | |

+-+

After reading the above analysis on mysql data operation, many readers must have some understanding. If you need to get more industry knowledge and information, you can continue to pay attention to our industry information column.

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report