Click here to Skip to main content
15,924,367 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
in my table suppose the data is like this

column1 column2
 1        50
 2        100
 3        50
 4        100


in the 5th row i want to aggreagate of column2

column1  column2
 1        50
 2        100
 3        50
 4        100
 final    75


how to do it ?
Posted
Updated 26-Jun-13 10:43am
v2

1 solution

Try this:

SQL
DECLARE @tmp TABLE (Col1 INT IDENTITY(1,1), Col2 INT)

INSERT INTO @tmp (Col2)
SELECT 50 AS Col2
UNION ALL SELECT 100
UNION ALL SELECT 50
UNION ALL SELECT 100

SELECT CONVERT(VARCHAR(30), Col1) As Col1, Col2
FROM @tmp
UNION ALL
SELECT 'Average', AVG(Col2)
FROM @tmp


Result:
Col1    Col2
1	50
2	100
3	50
4	100
Average	75
 
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