sum

MySQL: How can fetch SUM() of all fields in one Query?

Hi, I just want somthing like this: select SUM(*) from `mytable` group by `year` any suggestion? (I am using Zend Framework; if you have a suggestion using ZF rather than pure query would be great!) Update: I have a mass of columns in table and i do not want to write their name down one by one. No Idea?? ...

Use Linq to SQL to generate sales report

I currently have the following code to generate a sales report over the last 30 days. I'd like to know if it would be possible to use linq to generate this report in one step instead of the rather basic loop I have here. For my requirement, every day needs to return a value to me so if there are no sales for any day then a 0 is returned...

Sum of a row of an associative array using PHP?

Is there a php function that returns the sum of a row of an associative array? If not should I just use a counter and a foreach loop? Appreciate it! ...

In ruby on rails, is it possible to do a sum query with group by using the find_each batching?

I'm loading data from my database and I'm doing a sum calculation with a group by. ElectricityReading.sum(:electricity_value, :group => "electricity_timestamp", :having => ["electricity_timestamp = '2010-02-14 23:30:00'"]) My data sets are extremely large, 100k upwards so I was wondering if its possible to use the find_each to batch ...

select multiple columns using linq and sum them up

Hi, How can i select multiple columns and calculate the total amount. For example, in my database i got a few fields which are named: 5hunderedBills, 2hunderedBills, 1hunderedBills, etc. And the value of those fields are for example: 5, 2, 3 And the sum would be: 5hunderedBills * 5 + 2hunderedBills * 2 + 1hunderedBills * 3 How ca...

Best way to score and sum in Scala?

Is there a better way of doing this: val totalScore = set.foldLeft(0)( _ + score(_) ) or this: val totalScore = set.map(score(_)).sum I think it's quite a common operation so was expecting something sleeker like: val totalScore = set.sum( score(_) ) ...

LINQ aggregate / SUM grouping problem

I'm having trouble getting my head around converting a traditional SQL aggregate query into a LINQ one. The basic data dump works like so: Dim result = (From i As Models.InvoiceDetail In Data.InvoiceDetails.GetAll Join ih As Models.InvoiceHeader In Data.InvoiceHeaders.GetAll On i.InvoiceHeaderID Equals ih.ID Join p As Mo...

Linux shell sum columns

How can I sum (using Linux shell) numbers in a column? If possible, I don't want to use powerful tools like awk or perl. I want something like giveMeNumber | sum ...

Generating Running Sum of Ratings in SQL

I have a rating table. It boils down to: rating_value created +2 april 3rd -5 april 20th So, every time someone gets rated, I track that rating event in the database. I want to generate a rating history/time graph where the rating is the sum of all ratings up to that point in time on a graph. I.E. A person's r...

How to update records based on sum of a field then use the sum to calc a new value in sql

Below is what I'm trying to do with by iterating through the records. I would like to have a more elegant solution if possible since I'm sure this is not the best way to do it in sql. set @counter = 1 declare @totalhrs dec(9,3), @lastemp char(7), @othrs dec(9,3) while @counter <= @maxrecs begin if exists(select emp_num from #tt...

"Invalid Column Name" error thrown by Access Reports?

I am attempting to sum over a detail grouping on a specific field in Microsoft Access, and assign that sum to a field in the general grouping. When I try to run the report, I get an "Invalid Column Name" error with the detail field getting the error. Has anyone previously encountered this? If so, any ideas what might be causing it or how...

Rails ActiveRecord friendly code from a Complex Join, Sum, and Group query

PROBLEM Hello, I am having no luck trying to break down this SQL statement into ActiveRecord/Rails friendly code and I'd like to learn how I can avoid a find_by_sql statement in this situation. Scenario I have users that create audits when they perform an action. Each audit is of a specific audit_activity. Each audit_activity is wort...

Excel : sum of values depending of other values

Hi, What would be the equivalent Excel formula of this SQL query SELECT SUM(a) FROM table WHERE b < 0; A B ---- ---- 1 0 2 -1 3 4 5 -3 >> 7 ...

linq subquery child collection to string

Hi All, i am trying to figure out how to write a linq query that will return a child collections "name" property as a string. I have a BO that has a "options" property where the options are the "name" property of each option in an "order" object. I would like the result to look something like order.id = 12312 order.date = 12/03/10 or...

Linq to sum on groups based on two columns

Hi, I have a class as below: Class Financial { string Debit; string Credit; decimal Amount; } And I have a list with objects of this class, with multiple records. All I need is to perform a groupped sum, something like in sql Select debit, Credit, sum(amount) group by Debit, Credit I tried with a statement as below: f...

LINQ: how to transform list by performing calculations on every element

Hi, I have a class Class MyObject { decimal v1; decimal dv1; decimal v2; decimal dv2; } and a List<MyObject> ... I need to process every element of the list by adding dv1 to v1 and dv2 to v2 Something like (pseudo-syntax): myList.Transform(o=>o.v1+=o.dv1, o.v2+=o.dv2) How can I do this (obvious my pseudo-syntax...

Finding the sum of 2D Arrays in Ruby

Hi, I have an array of two dimensional Arrays. I want to create a new two dimensional array which finds the sum of these values in the 2D arrays. Sum at x,y of new array = Sum at x,y of arr1 + Sum at x,y of arr2 + .... |1,2,4| |1,1,1| |1,1,1| |2,4,6| |1,1,1| |1,1,1| |2,4,6| |1,1,1| |1,1,1| |2,4,6| |1,1,1| |1,1,1| Now adding the...

Add two hexBinarys with XPATH 1.0

Hi, my xml document looks somewhat like that (Values are both xsl:hexBinary): <Offsets> <Offset> <Name>ErrorOffset</Name> <Value>DD</Value> </Offset> <Offset> <Name>OtherOffset</Name> <Value>FF</Value> </Offset> </Offsets> <Value> <Name>Error1</Name> <Code>0...

c# datetime operator +=

i have two variables in type of DateTime, and i want to sum them, how can i do it? i get compilation error that says DateTime dosen't have operator += ...

SQL Summing Multiple Joins

I shortened the code quite a bit, but hopefully someone will get the idea of what i am tryign to do. Need to sum totals from two different selects, i tried putting each of them in Left Outer Joins(tried Inner Joins too). If i run wiht either Left Outer Join commented out, I get the correct data, but when i run them together, i get really...