同时针对两列排序(相交) [英] Order against two columns at the same time (intersecting)

查看:83
本文介绍了同时针对两列排序(相交)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其中包含字段 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

这篇关于同时针对两列排序(相交)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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