Which of the following MySQL fields can be obtained or queried?

Source: Internet
Author: User

Which of the following MySQL fields can be obtained or queried?

More: http://www.webyang.net/Html/web/article_138.html


Mysql is often used to query specific fields and occasionally needs to display a part of the value of a specific field. How can this problem be solved?

Then there is a fuzzy query, if you need to match a certain score in the middle, this time like is very embarrassing, there will be some irrelevant records, how to deal with this?

1. Obtain specific digits:
1. Take the last three characters of the url Field
 
 
  1. select SUBSTRING(url, -3) from link;
# This method can only be used for a fixed length. For example, the url contains a total of 8 characters, which can be written as follows:
 
 
  1. select RIGHT(`url`,length(`url`)-5) from link;
2. 3rd bits from the left (including the third bits)
 
 
  1. select SUBSTRING(url, 3) from link;
3. Take the three digits on the left
 
 
  1. select SUBSTRING(url, 1, 3) from link;
# This method can only be used for a fixed length. For example, the url contains a total of 8 characters, which can be written as follows:
 
 
  1. select LEFT(`url`,length(`url`)-5) from link;
4. Intercept (take 7 digits from 1st bits, for example, the sDate field value is)
 
 
  1. select SUBSTRING(sDate, 1,7) from forumdata;
The query result is 2013-06.

2. query specific digits:
1. Normal Fuzzy search
 
 
  1. select * from cm_order where ordersn like '%31%';
2. A field has 13 BITs and the last four or five bits are 31.
 
 
  1. select * from cm_order where SUBSTRING(ordersn, 9,2) = 31;
  2. SELECT * from cm_order where RIGHT(`ordersn`,length(`ordersn`)-8) like '31%';

This type of fuzzy query will produce a lot of irrelevant data, but this type can only be used for fixed-length fuzzy queries, which is much more efficient than normal fuzzy queries.

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.