Group By中的这个陈述是做什么的?真的有必要吗?

时间:2013-04-24 15:46:42

标签: sql sql-server select

FirstName+' '+LastName在以下Group By语句中做了什么,是否真的有必要?我尝试省略它,它产生了相同的结果。

SELECT FirstName+' '+LastName AS Employee, tblEmployee.EID, SUM(GrossAmount) AS [2011 Gross], SUM(NetAmount) AS [2011 Net], SUM(GrossAmount) - SUM(NetAmount) AS [2011 Taxes & WH]
FROM tblEmployee INNER JOIN tblPaycheck ON tblEmployee.EID=tblPaycheck.EID
WHERE YEAR(PayDate)=2011
GROUP BY tblEmployee.EID, LastName, FirstName, FirstName+' '+LastName
HAVING SUM(NetAmount)>=45000
ORDER BY LastName, FirstName, tblEmployeeA7.EID

1 个答案:

答案 0 :(得分:2)

它会产生相同的结果,因为姓氏和名字都存在,如果你删除了lastname和firstname而不是firstname +''+ lastname,也可以这样说。无论哪种方式,您都可以得到相同的结果

分组依据优先顺序排列。