在两个单独的字符串中查找相似的子字符串

时间:2018-08-31 17:31:36

标签: mysql

我有两个表格:一个表格的一列包含代表证券交易所的字符串(例如'BrsaItaliana'),另一个表格包含用于同一证券交易所的不同字符串(例如'意大利证券交易所')。如何检查前者的子字符串是否包含在后者中(例如,“ Italian”都包含在其中)?我已经尝试了以下查询,但是我意识到这是不正确的,因为该操作将eqs.primary_exchange视为“子字符串”,而我想使用eqs.primary_exchange的子字符串来定位常见的子字符串。

CREATE TABLE `yahoo_exchange_suffix`
(`exchange`        VARCHAR(40) NOT NULL COMMENT 'Long Name of Stock Exchange' ,
 `country`         VARCHAR(24) NOT NULL COMMENT 'Long name of country where exchange is located' ,
 `exchange_suffix` VARCHAR(10) COMMENT 'The code appended to ticker to denote a securities exchange.' ,
) COMMENT='Table provides list of used suffixes for non-US equity exchanges in order to properly interact with Yahoo Finance';

CREATE TABLE `equity_symbols`
(`ISIN`                   CHAR(12) NOT NULL COMMENT 'unique 12 character alphanumeric identifier for any security' ,
 `company_name`           VARCHAR(100) NOT NULL COMMENT 'Long company name attributed to security' ,
 `symbol`                 VARCHAR(18) NOT NULL COMMENT 'the string that identifies the security on local exchange' ,
 `bbg_symbol`             VARCHAR(24) NOT NULL COMMENT 'The string that identifies the security in bloomberg terminal' ,
 `company_description`    VARCHAR(1000) COMMENT 'Description of the company associated with ISIN' ,
 `domicile`               VARCHAR(10) NOT NULL COMMENT 'Location of headquarters' ,
 `category`               VARCHAR(32) NOT NULL COMMENT 'Type of security issued (e.g. COMMON STOCK, DEPOSITORY RECEIPT, etc)' ,
 `security_currency`      CHAR(3) NOT NULL COMMENT 'Currency denomination of security' ,
 `local_currency`         CHAR(3) NOT NULL COMMENT 'Currency issuer reports financials' ,
 `gics_sector_name`       VARCHAR(100) COMMENT 'String identifying the sector membership of security' ,
 `gics_industry_grp_name` VARCHAR(100) NOT NULL COMMENT 'String identifying the industry group of a security' ,
 `gics_industry_name`     VARCHAR(100) NOT NULL COMMENT 'String identifying a security\'s membership in an industry' ,
 `gics_sub_industry_name` VARCHAR(100) NOT NULL COMMENT 'String identifying the sub-industry membership of a security ' ,
 `gics_sector`            TINYINT COMMENT 'Code for securitys GICS sector' ,
 `gics_industry_grp`      SMALLINT COMMENT 'Code for GICS Industry Group' ,
 `gics_industry`          INT COMMENT 'Code for GICS industry' ,
 `gics_sub_industry`      INT NOT NULL COMMENT 'Code for GICS Sub-Industry' ,
 `primary_exchange`       VARCHAR(24) NOT NULL COMMENT 'Primary Exchange where security trades' ,
 `primary_mic`            CHAR(4) NOT NULL COMMENT 'Market Identification Code (MIC) for primary exchange' ,

 PRIMARY KEY (`ISIN`) COMMENT 'Unique 12 character alphanumeric code to identify securities.')
 COMMENT='This table will hold list of securities of interest to us whether for analytics, risk, research, etc. May ';


SELECT DISTINCT(eqs.primary_exchange) AS primary_exch,  
      y.exchange AS exch  
FROM equity_symbols eqs  
INNER JOIN yahoo_exchange_suffix y  
ON y.exchange LIKE CONCAT('%',eqs.primary_exchange,'%')

Details of tables with expected result

感谢您的宝贵时间,我们期待您的评论/建议。

0 个答案:

没有答案