In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
In this issue, the editor will bring you about how to access data in MySQL. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
How do you access data if you use MySQL?
If you use MySQL, the basic information of the phone is a separate table, and because the parameter information of different phones varies greatly, you also need a parameter table to save separately.
CREATETABLEIFNOTEXISTS`mobiles` (`id`int (10) unsignedNOTNULLAUTO_INCREMENT, `name`VARCHAR (100) NOTNULL, `brand`VARCHAR (100) NOTNULL,PRIMARYKEY (`id`)); CREATETABLEIFNOTEXISTS`mobile _ params` (`id`int (10) unsignedNOTNULLAUTO_INCREMENT, `mobile_ id`int (10) unsignedNOTNULL, `name`varchar (10) NOTNULL, `value`varchar (100) NOTNULL,PRIMARYKEY (`id`)); INSERTIN`mobiles` (`id`, `name`, `brand`) VALUES INSERTINTO`mobile _ params` (`id`, 'mobile_ id`, `name`, `value`) VALUES (1min1' standby time', '200'), (2)' design', 'straight board'), (3) 'standby time', '500'), (4) 'design', 'slide cover')
Note: for the convenience of demonstration, the paradigm design of relational database is not strictly followed.
How do you access data if you use MySQL?
If you want to query a phone with a standby time of more than 100 hours and a straight design, you need to query it as follows:
SELECT* From`mobile _ params`WHEREname = 'standby time' ANDvalue > 100th select * FROM`mobile _ params`WHEREname = 'Design' ANDvalue=' straight'
Note: parameter table for convenience, the values and strings are saved as strings. In practice, MySQL allows query of numeric types on fields of string type, but type conversion is needed, which will affect performance a little bit. Www.yzyedu.com
Take the intersection of the results of the two SQL entries to get the desired MOBILE_ID, and then query the mobiles table:
SELECT* From`mobiles`WhEREmobile _ idIN (MOBILE_ID)
If you use MongoDB, how do you access data?
If you use MongoDB, although you can theoretically adopt the same design scheme as MySQL, it will be boring, and it will not give full play to the advantages of MongoDB as a document database. In fact, if you use MongoDB, compared with MySQL, you can combine the two into one:
If you want to query a phone with a standby time of more than 100 hours and a straight design, you need to query it as follows:
Note: for a detailed description of the advanced usage such as $all,$elemMatch used in the query, please refer to the relevant instructions in the official documentation.
MySQL needs multiple tables, multiple queries to solve the problem, MongoDB only needs one table, a query can be done, compared to complete, compared to MySQL, MongoDB appears to be better.
The above is how to access the data in the MySQL shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are 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.