Click here to Skip to main content
15,896,727 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
This is my table...
select * from table1


--------------------------------------------------------------------------------
name v1 v2 v3
--------------------------------------------------------------------------------
a 1.2 1.2 2.0
b 2.1 2.4 3.4
c 1.0 8.5 0.56
d 2.7 2.5 2.6
--------------------------------------------------------------------------------

I need this result
--------------------------------------------------------------------------------
name v1 v2 v3
--------------------------------------------------------------------------------
avg 1.75 3.65 2.14(this new row)
a 1.2 1.2 2.0
b 2.1 2.4 3.4
c 1.0 8.5 0.56
d 2.7 2.5 2.6
--------------------------------------------------------------------------------

The row Avg is v1 values(1.2,2.1,1.0,2.7) is 1.75
v2 values (1.2,2.4,8.5,2.5) is 3.65
v3 values (2.0,3.4,0.56,2.6) is 2.14


the row avg is added dynamicly using avg()..


please anyone help me...
Posted

Perhaps something like:
SQL
select name, avg(v1),avg(v2),avg(v3)
from yourtable
group by name
with rollup
 
Share this answer
 
Comments
godbrother3 22-Dec-11 1:23am    
thank u...
Wendelius 22-Dec-11 1:24am    
You're welcome :)
godbrother3 22-Dec-11 1:40am    
now i also add one more new row Median. median is half of the value..
ex. (4,3,5) - (4) is median...

thank's lot..
Wendelius 22-Dec-11 1:44am    
Answered in your other question. If you want to use it with rollup, perhaps the easiest way (in sense of usage) is to create a custom aggregate.
thatraja 22-Dec-11 1:57am    
5!
You can use Union operator to add new row to result set.
e.g.

SQL
SELECT 'AVERAGE',AVG(V1),AVG(V2),AVG(V3) FROM TABLENAME
UNION
SELECT NAME,V1,V2,V3 FROM TABLENAME
ORDER BY 1
 
Share this answer
 
Comments
godbrother3 22-Dec-11 1:37am    
Thank's u...
below Query may help you..

SQL
select name,v1 from(
select 'Avg' as name,AVG(V1) as v1 from temp
union select name,v1 from temp)  as ss


Add v2,v3 columns ...
 
Share this answer
 
Comments
godbrother3 22-Dec-11 1:38am    
Thanks u...

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