MySQL more difficult a field sort of question

Source: Internet
Author: User
The result of a field is a JSON format such as

["12312", "I am Me", 0]

I would like to sort by the value of 12312, can I ask you to achieve it?

Reply content:

The result of a field is a JSON format such as

["12312", "I am Me", 0]

I would like to sort by the value of 12312, can I ask you to achieve it?

If your application is relatively simple and the amount of data is not very large, my advice is to take out the fields that need to be sorted as an indexed field. That is

"12312" | ["12312", "I am Me", 0]

If you think that your application scenario will become more complex, or the amount of data that needs to be indexed is very large, then consider MongoDB and directly deserialize the data into each field, that is

"12312" | "I Am Me" | 0

Use NoSQL or be cautious ... Can be done with MySQL, try to use MySQL

First, MySQL does not support Bson or JSON, even after the storage JSON is serialized. So the sort words have to be realized by themselves. This is not a good implementation, either from the MySQL side or from the script side, because a deserialization operation is required.
Second, you're storing like a document database (a NoSQL one), and MySQL is a relational database, so it's best to have a table and then move the data out of the way. Or use a document-based database such as MongoDB.

Reference @gaosboy
If you have a small amount of data and simply implement this function (without regard to efficiency)
Order BY cast (mid (fname, 3) as unsigned)

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.