Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am creating a pivot table in Sql server, am retrieving the information well but the repetitive values are not sum up. any idea on how to do it please.

What I have tried:

SQL
SELECT * FROM (SELECT [id],[name],[age],[month] FROM [testing].[dbo].[test_1] as [age])AS PT PIVOT(SUM([age]) for [month] in ([March],[April],[May],[June],[July],[August])) as [month]
Posted
Updated 28-Aug-21 7:28am
v2

1 solution

I think you want to sum the age of person having [id],[name],[age],[month]. If so then there is nothing wrong with your query. But i guess id can't be duplicate in your table. Please remove ID field and test your query you will defiantly got sum of age.

SELECT * FROM (SELECT [name],[age],[month] FROM [testing].[dbo].[test_1] )AS PT PIVOT(SUM([age]) for [month] in ([March],[April],[May],[June],[July],[August])) as [result]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900