Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
augustocolom
Starting Member
4 Posts |
Posted - 2010-09-09 : 10:51:17
|
| Hello, I wonder if you can bring the sum on a select,for example:Column Column right25 2525 5025 7525 100 it is possible? |
|
|
jcelko
Esteemed SQL Purist
547 Posts |
Posted - 2010-09-09 : 13:36:00
|
| A running total can be done in SQL, but you need to have a column that gives the ordering. CREATE TABLE SillyStuff(silly_seq INTEGER NOT NULL PRIMARY KEY, silly_value INTEGER NOT NULL);SELECT silly_seq, silly_value, (SELECT SUM(S2.silly_value) FROM SillyStuff AS S2 WHERE S1.silly_seq <= S2.silly_seq) AS running_tot FROM SillyStuff AS S1;Performance is terrible. Google the "SUM() OVER(RANGE..)" function in Standard SQL to see a better way to do this in other products. --CELKO--Books in Celko Series for Morgan-Kaufmann PublishingAnalytics and OLAP in SQLData and Databases: Concepts in Practice Data, Measurements and Standards in SQLSQL for SmartiesSQL Programming Style SQL Puzzles and Answers Thinking in SetsTrees and Hierarchies in SQL |
 |
|
|
|
|
|