关于独特功能过时的“提示”是否过时了?

时间:2012-07-09 21:30:52

标签: sql-server sql-server-2008 distinct

所以根据this website大约2007年,我们不应该使用distinct作为函数,即不要做像

这样的事情
select distinct(employeeID), salary
from salaryhist

这仍然是真的吗?我很难用查询搞清楚

2 个答案:

答案 0 :(得分:3)

DISTINCT是 一个功能。它从未(也可能永远不会)

表达式select distinct (employeeID)不是函数调用。

关键字select后跟关键字distinct,后跟列表达式(employeeID)

为了使事情更清楚,以下三点是相同的:

  • select distinct employeeID, (salary)
  • select distinct (employeeID), (salary)
  • select distinct employeeID, salary

所有内容都相同,因为employeeID(employeeID)是相同的:对列的引用。

答案 1 :(得分:0)

与查询相比,你必须得到更好的结果,

从employeehist组中选择employeeID,sum(salary)by employeeID