I have a SQL query that involves a PIVOT command that creates the correct table but now I need to GROUP BY one of the columns.
When I try to add the GROUP BY statement, it is returning the following error: "Column 'PivotTable.1' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."
SELECT [Load ID],[1],[2],[3],[4]
FROM TMS_Load_Stops
PIVOT (
MIN([Stop Zip])
for [Sequence] IN ([1],[2],[3],[4])
) PivotTable
;
The original code yields the below results:

And I would like the results to be as follows (values are random numbers for explanation purposes):
