ORDER BY items must appear in the select list if SELECT DISTINCT is specified

♀尐吖头ヾ 提交于 2019-12-02 08:15:38

DISTINCT doesn't allow any expression in the ORDER BY that is not also in the SELECT list (even if, as in this case, the expression could only yield one specific value for each distinct row). You can use.

SELECT Batchno,
       LocationId
FROM   Ordertbl
GROUP  BY Batchno,
          LocationId
ORDER  BY CASE
            WHEN[LocationId] = 3 THEN 0
            ELSE 1
          END,
          [LocationId] 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!