如何在SQL中的同一张表中绑定单个列中的不同列 [英] How to bind different columns in a single from the same table in sql

查看:77
本文介绍了如何在SQL中的同一张表中绑定单个列中的不同列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是基表结构

ID RegNo NewID NewRegNo
1 a001--
2 a002--
3 a003 1 a004
4 a005--
5 a006 2 a007
6 a008 3 a008

现在我想得到这个

ID RegNo
1 a001
2 a002
3 a004
4 a005
5 a007
6 a008

Here is the base table structure

ID RegNo NewID NewRegNo
1 a001 - -
2 a002 - -
3 a003 1 a004
4 a005 - -
5 a006 2 a007
6 a008 3 a008

Now i want to get this

ID RegNo
1 a001
2 a002
3 a004
4 a005
5 a007
6 a008

推荐答案



您可以在使用语法时使用大小写.
为此尝试以下查询.

Hi,

you can use case when syntax for that.
Try the following query for that.

select id,
regno = case when NewRegNo is null then RegNo else NewRegNo end
from Table_1



谢谢,
Viprat



Thanks,
Viprat


这篇关于如何在SQL中的同一张表中绑定单个列中的不同列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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