本文介绍了SQL 比较两列的相同值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 SQL Server 2012,我有两列要进行比较.两者都在同一张桌子上,所以不需要连接.

With SQL Server 2012, I have two columns that I would like to compare. Both are on the same table, so no joins are needed.

基本上我需要比较两列,例如 scan1scan2,如果它们的值匹配,那么我需要一个 1,否则.匹配结果将输出到AS Results.

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. The results of the match would output to AS Results.

推荐答案

类似 SELECT .... , CASE WHEN scan1 = scan2 THEN 1 ELSE 0 END AS is_equal FROM table1 应该可以.

这篇关于SQL 比较两列的相同值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 20:15