同时针对两列排序(相交)

编程入门 行业动态 更新时间:2024-10-27 22:32:05
本文介绍了同时针对两列排序(相交)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个表,其中包含字段 CommonName 和 FirstName .只有一个字段具有数据,而没有两个字段.有没有一种方法可以在SQL Server上以相交的方式对行进行排序?

I have a table with the fields CommonName and FirstName. Only either field has data, never both. Is there a way to order rows in an intersecting manner on SQL Server?

示例:

CommonName FirstName Bern Wade Ashley Boris Ayana

我要按以下顺序排序记录:

I want records ordered like this:

CommonName FirstName Ashley Ayana Bern Boris Wade

这可能吗?如果可以,怎么办?

Is this possible, and if so, how?

推荐答案

ORDER BY CASE WHEN CommonName is null THEN FirstName ELSE CommonName END

更多推荐

同时针对两列排序(相交)

本文发布于:2023-10-28 02:37:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535263.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!