假如有如下表
ID FatherID string1 string2 date1 int1
1 NULL NULL fff NULL NULL
2 NULL ffsd NULL NULL NULL
3 1 NULL thrth NULL NULL
4 NULL 单纯 NULL NULL NULL
5 2 NULL 傻 NULL NULL
6 4 专业 NULL NULL NULL
字段string1和strin2互斥,当一个有内容时,另一个为空,在界面上为了显示的要求,要两个字段合在一起显示,则可以用以下sql语句来查询。
select Id,fatherid ,case when string1 is null then string2 else string1 end as name2 from table_1
查询出来的结果如下
Id fatherid name2
1 NULL fff
2 NULL ffsd
3 1 thrth
4 NULL 单纯
5 2 傻
6 4 专业
知识简章。文章写得详细。