user133466
user133466

Reputation: 3415

What does this statement in Group By do? Is it really necessary?

What does FirstName+' '+LastName do in the following Group By statement, is it really necessary? I tried omitting it, and it produced the same result.

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

Upvotes: 0

Views: 86

Answers (1)

SpaceApple
SpaceApple

Reputation: 1327

It would produce the same result, since the last name and first name are present, this could also be said if you removed lastname and firstname instead of the firstname + ' ' + lastname. Either way you get the same results

Group by takes columns by precedence.

Upvotes: 2

Related Questions