如何在Sql中比较2列并在另一列中显示结果 [英] How to Compare 2 columns in Sql and Display the result in another Column

查看:97
本文介绍了如何在Sql中比较2列并在另一列中显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Student_ID名字出生日期性别等级CorRes StuRes Newcol_compare

1管家4-10-91 M 1 ABCD DCCD DC **





上面是我的表我想要一个查询或程序,我可以比较StuRes和CorRes然后将结果保存在另一个名为Newcol_compare的列中,如果它们相等则将其放在Newcol_compare中,如果输入错误然后显示错误的输入,因为它..任何人请帮助我查询器程序我是新的SQL PLease帮助.. ???

Student_ID First Name Birthdate Gender class CorRes StuRes Newcol_compare
1 Butler 4-10-91 M 1 ABCD DCCD DC**


Hi above is my Table I want a query or procedure where i could compare StuRes and CorRes and then Keep the result in another Column called Newcol_compare where if they are equal then place * in Newcol_compare and if wrong input then show wrong input as it is.. can any one please help me with queryor procedure i am very new to SQL PLease help..???

推荐答案

使用此 -



use this-

Select Newcol_compare= CASE WHEN  CorRes=StuRes THEN '*'  ELSE Newcol_compare END From Table_Name





如果有帮助则标记为答案,否则,让我知道问题我会再解释..



mark as answer if helps, otherwise, let me know the problem i will explain again..


这篇关于如何在Sql中比较2列并在另一列中显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆