如何在Excel中比较两列?

时间:2016-08-02 06:09:52

标签: sql-server excel excel-formula

我有这样的excel表:

column1     column2
a            b
b            w
c            a
d            c
e            z
f            k
g            t
h            y
i            j
j            d
k            e
l            f

我希望将column1的第一个值 a 与column2的每个值进行匹配。如果找到值,我想在下一栏中显示一些消息,例如找到,或者突出显示值本身,然后在列2中找到值 b ,依此类推。

Objective:

实际上我在sql中有两个表有多个列,这些表也有一些常见的列。我只是想找出匹配的列名。如果有人还有其他方式,请告诉我。 提前致谢。

1 个答案:

答案 0 :(得分:0)

这样的事情应该适用于SQL Server

;with cte as
(
SELECT *
FROM   (VALUES ('a','b'),
               ('b','w'),
               ('c','a'),
               ('d','c'),
               ('e','z'),
               ('f','k'),
               ('g','t'),
               ('h','y'),
               ('i','j'),
               ('j','d'),
               ('k','e'),
               ('l','f') ) tc (column1, column2) 
)
SELECT column1,
       CASE
         WHEN EXISTS (SELECT 1
                      FROM   cte b
                      WHERE  a.column1 = b.column2) THEN 'Found'
         ELSE 'Not Found'
       END AS Identifier
FROM   cte a 

<强>结果:

+--------+--------------+
|column1 |  Identifier  |
+--------+--------------+
| a      | Found        |
| b      | Found        |
| c      | Found        |
| d      | Found        |
| e      | Found        |
| f      | Found        |
| g      | Not Found    |
| h      | Not Found    |
| i      | Not Found    |
| j      | Found        |
| k      | Found        |
| l      | Not Found    |
+--------+--------------+