It is recommended to store the average value as decimal instead of
varchar , as % can be added in presentation layer.
Here is the query that does the calculation, substring and cast was
needed as average column is varchar.
removed substring logic, as they are float columns, as per OP
set [col 2] = T.avgValue
select avg( [col 1] ) as avgValue
You could change the scope of your second SUM() function to reference
those values or a different group. Here's a good article from MSDN:
case based aggregation is one way to do this in single query.
SELECT AVG(case when dateColumn > startRange1 && dateColumn
< endRange1 then column1 end) as range1Avg,
AVG(case when dateColumn > startRange2 && dateColumn
< endRange2 then column1 end) as range2Avg
How to find average:
Add up all elements in the Arraylist
divide by the ArrayList's size
How to find median:
Use Collections.sort() on the ArrayList to sort it
get the element at the middle of the ArrayList (ArrayList's size/2)