" ORDER BY"之后的不同列在SQL Server 2014中

时间:2018-04-18 08:07:29

标签: sql-server sql-server-2014

我希望在 ORDER BY points.pPoint 之后区分列。
这是点表图:
enter image description here 我想在右侧看到下面的图像,但是得到左侧的结果:

image

这是我的代码:

SELECT TOP(6) MedicalExpertise.meid
FROM   physician INNER JOIN
       MedicalExpertise ON physician.meid = MedicalExpertise.meid INNER JOIN
       points ON physician.phId = points.phID
ORDER BY points.pPoint DESC

3 个答案:

答案 0 :(得分:2)

也许是这样的?

SELECT   DISTINCT meid
FROM     (   SELECT   TOP ( 6 ) MedicalExpertise.meid
             FROM     physician
                      INNER JOIN MedicalExpertise ON physician.meid = MedicalExpertise.meid
                      INNER JOIN points ON physician.phId = points.phID
             ORDER BY points.pPoint DESC ) d
ORDER BY 1 DESC;

答案 1 :(得分:0)

只需使用distinct关键字, 例如: SELECT DISTINCT column1,column2,... FROM table_name;

答案 2 :(得分:0)

你能编辑一下你真正想要的原始问题吗?在获得分离之前,是否必须按任何列进行分组?请更新问题。