sum

Making a MySQL view easier to update & load

I'm having a view that's actually a combination of 2 other views, which in they turn are the split of Table1 join Table2. The split in the 2 view is based on whether the column of the table1 EnterDate=curDate(), which determines the way a new column is calculated ( NewColumn=(Table2.Cpx-Table1.Px)*Table1.Size if EnterDate=curdate() and N...

Accurate evaluation of 1/1 + 1/2 + ... 1/n row

I need to evaluate the sum of the row: 1/1+1/2+1/3+...+1/n. Considering that in C++ evaluations are not complete accurate, the order of summation plays important role. 1/n+1/(n-1)+...+1/2+1/1 expression gives the more accurate result. So I need to find out the order of summation, which provides the maximum accuracy. I don't even know wh...

SQL Running Sum with flags at certain amounts

I am trying to create a query to sum total gifts given by a certain person, but to add a flag on the individual gift when the total giving hits $500 (I don't need to sum past that). I have the Persons ID, the gift size, and the gift date. for example: ID gift_date gift_amt --------- ----------- -------------- 1...

MySQL SUM when using GROUP BY not working

Let's say we have this table: Symbol | Size A | 12 B | 5 A | 3 A | 6 B | 8 And we want a view like this: Symbol | Size A | 21 B | 13 So we use this: Select Symbol, sum(Size) from table group by Symbol order by Symbol ASC But instead we get this: Symbol | Size A | 12 B | 5 What am I...

LINQ to SQL - Select SUM with a WHERE

I'm having trouble getting a Linq to Sql query to work. Basically, I want the sum of a column in a table for only rows matching a certain condition. A simplified version is this: Orders = order that contains products OrderProducts = relational table containing products that are in an order Products = table containing information about...

MDX ability to calculate ratio of sums from child levels

I'm very much a novice at MDX, and have no idea how to approach this problem. I'd appreciate any help, even if just pointers to where relevant functions are explained. I need to be able to calculate the ratio of sums, where the numerator is a trivial SUM measure, but the denominator is the sum of dimension-specific values. For those k...

XSLT to sum product of two attributes

Hi All I have the following XML source structure: <turnovers> <turnover repid="1" amount="500" rate="0.1"/> <turnover repid="5" amount="600" rate="0.5"/> <turnover repid="4" amount="400" rate="0.2"/> <turnover repid="1" amount="700" rate="0.05"/> <turnover repid="2" amount="100" rate="0.15"/> <turnover repid="1"...

Summation notation in Haskell

On the Wikipedia page about summation it says that the equivalent operation in Haskell is to use foldl. My question is: Is there any reason why it says to use this instead of sum? Is one more 'purist' than the other, or is there no real difference? ...

using an aggregate function to narrow my query

I want to do something like this: SELECT locations.id, places.id, scannables.id, SUM(scannables.available) FROM `scannables` INNER JOIN places ON scannables.place_id = places.id INNER JOIN locations ON places.location_id = locations.id WHERE locations.id = 2474 AND scannables.bookdate BETWEEN '2009-08-27' and date_add('2009-08-27', IN...

PagedCollectionView implement Extensions (SUM) after filter is applied

Hi, I have a PagedCollectionView over an observablecollection. When a series of filters are applied to the PagedCollectionView the datagrid binding to the PagedCollectionView displays the filtered data. However, I have a textblock where I display sum of a particular property within the observablecollection(or column in the datagrid). I d...

[SQL] Getting the sum of several columns from two tables

I want to get the sum of several columns from 2 different tables (these tables share the same structure). If I only consider one table, I would write this kind of query: SELECT MONTH_REF, SUM(amount1), SUM(amount2) FROM T_FOO WHERE seller = XXX GROUP BY MONTH_REF; However, I would like to also work with the data from the ...

PHP Array_Sum on multi dimensional array

If I have a multi dimensional array in PHP like so... [0] => Array ( [url] => http://domain1.com [domain] => domain1.com [values] => Array ( [character_length] => 25 [word_count] => 7 ) ) [1] => Array ( [url] => http://domain2.c...

SQL Max(something,0) type solution

Hi I would like to do the following: SELECT sum(max(field-10,000,0)) from TABLE as in, I want to have field-10,000 summed up, but if field-10,000 < 0 then I want it to add 0. any suggestions? Karl ...

sum in query / subquery

Table has the following info: date |vendor|sales|percent| -------------------------- 2009-03-03| 10 |13.50| 1.30 | 2009-03-10| 10 |42.50| 4.25 | 2009-03-03| 21 |23.50| 2.30 | 2009-03-10| 21 |32.50| 3.25 | 2009-03-03| 18 |53.50| 5.30 | 2009-03-10| 18 |44.50| 4.45 | I want it to sort into separate tables depending on d...

has_many and sum named_scope

I have this situation: Stories has many Tasks Tasks have an integer called hours_left I need a named scope to find Stories which all its tasks has more than 0 hours left. Based on this post. I wrote this: class Story has_many :tasks named_scope :uncompleted, { :joins=>["INNER JOIN tasks ON tasks.story_id = stories.id"], ...

Cumulative DQL with Doctrine

Hello Im having a hard time working out a proper DQL to generate cumulative sum. I can do it in plain SQL but when it comes to DQL i cant get hold of it. Here is how it looks in SQL: SELECT s.name, p.date_short, p.nettobuy, (select sum(pp.nettobuy) as sum from price pp where pp.stock_id = p.stock_id and p.broker_id = pp.brok...

How to sum array members in Ruby?

I have an array of integers. For example: array = [123,321,12389] Is there any nice way to get the sum of them? I know, that sum = 0 array.each { |a| sum+=a } would work. ...

Linq: Sum of int

I am getting "The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type" When executing Sum() of my empty statement. ResultView works fine, but either var r = from v in DataContext.Visits join bs in DataContext.BaseContents on v.BaseContentID equals bs.Id where (bs.CreatedBy ...

Avg of a Sum in one query

I would like to know if I can get the average of a sum in one single SQL SERVER request, Have tried to do it with the following request but it doesn't work: SELECT t.client, AVG(SUM(t.asset)) AS Expr1 FROM TABLE t GROUP BY t.client ...

Adding up all the positive numbers in Excel

Is there a way to add up all of the positive numbers in a row/column but ignoring all of the negative numbers? Like SUM(), except that it ignores negative numbers. Would I have to use VBA? If so, how would I do it in VBA? If it can't be done in Excel, can it be done in OpenOffice Calc? ...