T-SQL - 带有千位分隔符的 ORDER BY 成功

T-SQL - Successful ORDER BY with thousand separator

此查询要求 ActualTotal 以最大值排序,但是正如您从屏幕截图中看到的那样,这并没有完全奏效。有没有办法做到这一点?这是我当前的代码:

SELECT 
    m.name, 
    FORMAT(x.ComTotal,'N0') AS Total_2020, 
    FORMAT(y.Totals,'N0') AS Some_2020, 
    FORMAT(x.ComToTal + y.Totals,'N0') AS ActualTotal
FROM 
    Mees m
LEFT JOIN 
    View_2020_Listx_Jan2020 x ON m.name = x.m
LEFT JOIN 
    View_Listy_2020_Totals y ON m.name = y.name
ORDER BY 
    ActualTotal DESC;

非常感谢任何帮助,谢谢。

你可以这样写。

SELECT 
    m.name, 
    FORMAT(x.ComTotal,'N0') AS Total_2020, 
    FORMAT(y.Totals,'N0') AS Some_2020, 
    FORMAT(x.ComToTal + y.Totals,'N0') AS ActualTotal
FROM 
    Mees m
LEFT JOIN 
    View_2020_Listx_Jan2020 x ON m.name = x.m
LEFT JOIN 
    View_Listy_2020_Totals y ON m.name = y.name
ORDER BY 
    x.ComToTal + y.Totals DESC

刚刚使用 REPLACE 函数按顺序排列。

替换代码ORDER BY ActualTotal DESC; ORDER BY REPLACE(ActualTotal, ',', '') DESC;