Please advise me if you know the terminology to describe to following action:
Input
dfips dcounty context sumton
19001 Adair County mail 6521.79995560646
19001 Adair County Rail 38411.5996840298
Output:
dfips dcounty mail_sumton rail_sumton
19001 Adair County 6521.79995560646 38411.5996840298
I want to convert the input to the output, but I am not sure how to describe such action. The best I can come up with is convert aggregation results into columns.
The simple crosstab version of a
pivot()
would look like this:You can use aggregate function
sum
(ormax
as per your needs) to achieve this.Alternatively, you can use the
PIVOT
function within query -- see docs at https://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspxConditional aggregation