我有CommonName
和FirstName
的字段的表。只有两种字段数据,不可能兼顾。有没有办法在SQL Server上的交叉方式命令行?
例:
CommonName FirstName
Bern
Wade
Ashley
Boris
Ayana
我想订购这样的记录:
CommonName FirstName
Ashley
Ayana
Bern
Boris
Wade
这是可能的,如果是这样,怎么样?
使用CASE
statement选择该行的价值和ORDER BY
这一点。
ORDER BY CommonName + FirstName
,适当ISNULL(<column>, '')
如果他们是空。
ORDER BY
CASE
WHEN CommonName is null
THEN FirstName
ELSE CommonName
END
order by coalesce(CommonName, FirstName)