[英]SQL compare two columns for same value
With SQL Server 2012, I have two columns that I would like to compare. 对于SQL Server 2012,我有两列要比较。 Both are on the same table, so no joins are needed. 两者都在同一张表上,因此不需要联接。
Basically I need to compare two columns, for example scan1
and scan2
and if their value's match, then I need a 1
, else 0
. 基本上,我需要比较两列,例如scan1
和scan2
,如果它们的值匹配,则需要1
,否则需要0
。 The results of the match would output to AS Results. 匹配结果将输出到AS结果。
诸如SELECT .... , CASE WHEN scan1 = scan2 THEN 1 ELSE 0 END AS is_equal FROM table1
应该SELECT .... , CASE WHEN scan1 = scan2 THEN 1 ELSE 0 END AS is_equal FROM table1
。
You can go like: 您可以像这样去:
SELECT CASE WHEN Scan1 = Scan2 THEN 1
ELSE 0 END AS ColumnAlias
FROM YourTable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.