MySQL Gets or queries a specific few of the database fields

Source: Internet
Author: User

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


MySQL is often used to query specific fields, and occasionally need to show a certain part of the value in a particular field, how to deal with it?

Then there are fuzzy queries, if you need to match some part of the value of the middle, this time like is very awkward, will be more irrelevant records, and how to deal with it?

First, get the specific few:
1. Take the three-bit character after the URL field
 
   
  
  1. Select SUBSTRING (url,-3) from link;
#这种只能针对固定长度, the URL is a total of 8 characters, you can follow this notation
 
   
  
  1. Select Right (' url',length(' url ')-5) from link ;
2, starting from the left 3rd place (including the third place)
 
   
  
  1. Select SUBSTRING (url,3) from link;
3, take the left 3 digits
 
   
  
  1. Select SUBSTRING (url,1,3) from link;
#这种只能针对固定长度, the URL is a total of 8 characters, you can follow this notation
 
   
  
  1. Select Left (' url',length(' url ')-5) from link ;
4, Intermediate intercept (starting from the 1th bit to take 7 bits, such as the Sdate field value is 2013-06-07)
 
   
  
  1. Select SUBSTRING (sdate,1,7) from forumdata;
The query results are 2013-06.

Second, the query specific several:
1, the normal fuzzy query
 
   
  
  1. Select* from where '%31% ';
2, a field total of 13 bits, query the bottom four or five bits 31
  
 
  1. select * Span class= "PLN" > from Cm_order where SUBSTRING ( ORDERSN 9 2 = 31
  2. SELECT * from Cm_order where right(' ordersn ', Length(' ordersn ')-8) like ' 31% ' ;

If the normal fuzzy query will come out a lot of irrelevant data, but this only for fixed-length fuzzy query, efficiency than normal fuzzy query much better.

MySQL Gets or queries a specific few of the database fields

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.