If you don't use OLAP functions, then you have to do a weird self-join on the table:
SELECT a.ColA, a.ColB, SUM(b.ColB) AS ColX
FROM #MyTempTable AS a
JOIN #MyTempTable AS b
ON a.ColA <= b.ColA
GROUP BY a.ColA, a.ColB
This gives you the raw cumulative SUM. You can definitely use that as a sub-query to get the answer, noting that to get the percentage, you need to divide the cumulative sum by the gross sum:
SELECT ColA, ColB, ColX / (SELECT SUM(ColB) FROM MyTempTable) AS ColC
FROM (SELECT a.ColA, a.ColB, SUM(b.ColB) AS ColX
FROM #MyTempTable AS a
JOIN #MyTempTable AS b
ON a.ColA <= b.ColA
GROUP BY a.ColA, a.ColB
) AS X
ORDER BY ColA
You may be able to write just:
SELECT a.ColA, a.ColB, SUM(b.ColB) / (SELECT SUM(ColB) FROM MyTempTable) AS ColC
FROM #MyTempTable AS a
JOIN #MyTempTable AS b
ON a.ColA <= b.ColA
GROUP BY a.ColA, a.ColB
ORDER BY a.ColA
Multiply the ColC expression by 100 to get a percentage instead of a fraction.
Tested against IBM Informix 11.70.FC2 on Mac OS X 10.7.3, both the queries with division work, producing the same answer (and I note that I get 0.81 instead of 0.71 as required in the question):
Name1 218 0.34603174603174603174603174603175
Name2 157 0.5952380952380952380952380952381
Name3 134 0.80793650793650793650793650793651
Name4 121 1.0
You might have to use a CAST to ensure the division is done using floating point instead of integer arithmetic — as you can see, that wasn't necessary with Informix (the SUM is a floating point decimal anyway, just in case the table has billions of rows in it, not just 4 of them). I could improve the presentation using ROUND(xxxx, 2)
to get just 2 decimal places; a cast to DECIMAL(6,2) would achieve the same result, but the client should be responsible for the presentation, not the DBMS.