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
- Select SUBSTRING (url,-3) from link;
#这种只能针对固定长度, the URL is a total of 8 characters, you can follow this notation
- Select Right (' url',length(' url ')-5) from link ;
2, starting from the left 3rd place (including the third place)
- Select SUBSTRING (url,3) from link;
3, take the left 3 digits
- Select SUBSTRING (url,1,3) from link;
#这种只能针对固定长度, the URL is a total of 8 characters, you can follow this notation
- 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)
- Select SUBSTRING (sdate,1,7) from forumdata;
The query results are 2013-06.
Second, the query specific several:
1, the normal fuzzy query
- Select* from where '%31% ';
2, a field total of 13 bits, query the bottom four or five bits 31
- select * Span class= "PLN" > from Cm_order where SUBSTRING ( ORDERSN 9 2 = 31
- 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