Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL Server简单比较_Sql_Sql Server - Fatal编程技术网

SQL Server简单比较

SQL Server简单比较,sql,sql-server,Sql,Sql Server,如何比较以下两列: Column A Column B Column c 10,16,56,76 56 good 2,64,74,66 77 missing 您不应该在列中存储值列表。您不应该将数字存储在字符串中。但是让我假设你在这件事上没有选择,坚持别人非常非常非常糟糕的决定 您可以像使用一样使用: select t.*, (case when concat(',', A, ',') like concat('%,'

如何比较以下两列:

Column A        Column B  Column c
10,16,56,76      56       good
2,64,74,66       77       missing

您不应该在列中存储值列表。您不应该将数字存储在字符串中。但是让我假设你在这件事上没有选择,坚持别人非常非常非常糟糕的决定

您可以像使用一样使用:

select t.*,
       (case when concat(',', A, ',') like concat('%,', B, ',%')
             then 'Good' else 'Missing'
        end)
from t;
您不应该将值存储在字符串中,而是应该有一个单独的连接表,每个表和每个实体有一行。然后查询将使用
exists

select t.*,
       (case when exists (select 1 from junction j where j.entity_id = t.entity_id and j.a = t.b)
             then 'Good' else 'Missing'
        end)
from t;

这可能也会有更好的性能。

永远不要将数据存储为逗号分隔的项。这只会给你带来很多麻烦。根据问题指南,请展示你的尝试,并告诉我们你(在本网站或其他地方)发现了什么,以及为什么它不能满足你的需求。提供你期望的结果,并实际提出一个问题。