简体   繁体   English

如何确定一列中的字符串是否在另一列中?

[英]How to determine if a string from one column is in another column?

I need to see if a string from one column is located in another column. 我需要查看一列中的字符串是否位于另一列中。 What's a good way to do that please? 请问有什么好方法吗?

Table: 表:

在此处输入图片说明

Desired Results: 所需结果:

在此处输入图片说明

SQL: SQL:

DROP TABLE ##SCHOOLS

CREATE TABLE ##SCHOOLS(
SchoolName   varchar(50),
ChoiceSchool varchar(50),
)

INSERT INTO ##SCHOOLS
(SchoolName, ChoiceSchool)
VALUES 
('Smith HS', 'Smith'),
('Jones High', 'Jones'),
('Eagle Elementary School', 'Eagle'),
('Hawk ES', 'Dunham'),
('No241', 'Harris'),
('Brookfield Middle', 'Brookfield')

SELECT 
ChoiceSchool
,SchoolName
FROM ##SCHOOLS

Thank you for your help. 谢谢您的帮助。

You can use like operator. 您可以使用like运算符。 For your particulare case it should be: 对于您的特殊情况,应为:

SELECT 
    ChoiceSchool,
    SchoolName
FROM ##SCHOOLS
WHERE SchoolName like '%' + ChoiceSchool + '%'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将一部分字符串从一列复制到另一列 - copy part of string from one column into another 从一列中选择,然后插入附加了一些字符串的另一列中? - Select from one column and insert into another column with some string appended? Postgresql 从另一列中减去一列中的逗号分隔字符串 - Postgresql subtract comma separated string in one column from another column 在SQL中将数据字符串的一部分从一列复制到另一列 - Copy section of data string from one column to another column in SQL 如何根据 SQL 中另一表的匹配字符串列更新一个表的数字列 - How to update numerical column of one table based on matching string column from another table in SQL 如何从另一个表的列更新一个表的一列 - how to update one column of one table from column of another table 如何使用一个表的列中的值来确定要在另一个表的 select 中使用的列 - How to use value in one table's column to determine the column to use in a select in another table 如何用一个来自另一个表的列的值约束一个列? - How to constraint one column with values from a column from another table? 如何从另一列中计算出一列? - how to calculate one column from another columns? 如何将值从一列连接到另一列 - How to join values from one column to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM