Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Whether one field of sql contains another field

2025-02-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

/ * Navicat MySQL Data TransferSource Server: testSource Server Version: 50528Source Host: localhost:3306Source Database: testTarget Server Type: MYSQLTarget Server Version: 50528File Encoding: 65001Date: 2015-03-13 11:25:34*/SET FOREIGN_KEY_CHECKS=0 -Table structure for queryreptycode-- DROP TABLE IF EXISTS `queryreptycode`; CREATE TABLE `queryreptycode` (`id` int (11) NOT NULL, `code` varchar (50) DEFAULT NULL, `codeRepty` varchar (50) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 -Records of queryreptycode-- INSERT INTO `queryreptycode` VALUES ('1th,' 1th,'1'); INSERT INTO `queryreptycode` VALUES ('2stories,' 2stories, '2partners,' 3countries 4countries'); INSERT INTO `queryreptycode` VALUES ('3stories,' 3cycles,'1 ')

The data are:

Select DISTINCT Q1.idINNER JOINqueryreptycode as Q1.coderection Q1.codeRepty from queryreptycode as Q1 codeRepty Q2 where INSTR (Q1.`code`,'%'+ Q2.codeReptyweights%')

Principle:

The function INSTR tells the user whether one of the strings (parameters) is in another string (also parameters).

The specific syntax format is as follows:

INSTR (string,substring [, start [, occurrence]])

Where:

String string to be queried

The string that substring is searching for

Start indicates the character position at which to start the search. The default value is 1, that is, the search will start with the first character of the string. If the parameter is negative, the location of the search is calculated from the right instead of the default from the left

Occurrence specifies the number of occurrences of the substring you are trying to search for. The default value is 1, which means that you want it to appear for the first time.

This function feeds back an index order value, where the substring to be searched is found. The following example indicates the use of the INSTR function:

INSTR ('AAABAABA','B') = 4

INSTR ('AAABAABA','B',1,2) = 7

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report