In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the example analysis of Mysql bit operation to simplify one-to-many relationship, which is very detailed and has certain reference value. Friends who are interested must finish it!
Grammar
The bit that both bitwise and binary bits are both 1 is set to 1.
|: bitwise or, if one bit of the binary bit is 1, it is 1.
^: XOR by bit, when the binary number of the corresponding bit is different, the result of the corresponding bit is 1; if both corresponding digits are 0 or 1, the result of the corresponding bit is 0.
Principle
Convert $a = 6 into binary 110$ b = 3 convert binary to 11$ a & $b that is 110 and 11 set the 1 bit in both $an and $b to 1, and fill 0 if there are not enough digits. That is, the operation result of 110 and 011 is 010, and the decimal result is 2.
Application scenario
Each scenic spot contains many attributes, such as the month suitable for tourism, we may generally do it in two ways:
Is to add a varchar field, which is separated by a special symbol between each month, for example: "1meme2pence22pence65pc7"
Establish a relational table, where you can't use a number of 1-12 to represent the month, but instead use the number 1, 2, 4, 8, 16, 64, 128, 512, 1024, 2048, 4096. If it is multiple months, it can be combined and added to each other, and then stored as a value.
For example, in October and December, you can store the value of 1" 512 "4096" 4609 "4096.
This technique is suitable for one-to-many scenarios with fewer attributes, one or more can be stored, and if there are too many, it is recommended to try relational tables. Commonly used properties are: month, message reminder type, various limited type combinations, and so on.
Use skills:
-- add a category with "|" SELECT (4 | 2 | 1);-- = 7 SELECT-remove a category and use "^" SELECT 7 ^ 1-when we need to query scenic spots in a certain month, such as March, we can use the following statement: SELECT * FROM `spots`spots`month` & 4 = 4 When setting a scenic spot for a certain month, for example, setting 4325 scenic spots for February, you can use the following sentence: UPDATE `spots` SET `month` = `month` | 2 WHERE `id` = 4325Method-when you unset the month of a scenic spot, you can use the following statement: UPDATE `spots`SET`month` = `month` ^ 2WhERE`id` = 4325color-query the data suitable for multiple months at the same time, for example, query the scenic spots with November 12 and January. Add up the corresponding values for the three months, and the result is 6145, and then use this value to query: SELECT * FROM `spots` WHERE `month` & 6145 = 6145color-query as long as it is appropriate, SELECT * FROM `spots`WHERE (`month` & 4096 = 4096) or (`month` & 2048 = 2048) or (`month` & 1 = 1) above are all the contents of the article "sample Analysis of Mysql bit Operations to simplify one-to-many Relations" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.