sum

SQL not a single-group group function

When I run the following SQL statement: SELECT MAX(SUM(TIME)) FROM downloads GROUP BY SSN It returns the maximum sum value of downloads by a customer, however if I try to find the social security number that that max value belongs to by adding it to the select statement: SELECT SSN, MAX(SUM(TIME)) FROM downloads GROUP BY SSN I get ...

xsl to produce summation value for each attribute

I want to use XSLT to calculate the summation value of amount the input is: <FileHeader> <Item amount="500" /> <Item amount="600" /> <Item amount="400" /> <Item amount="700" /> <Item amount="100" /> <Item amount="900" /> ...

Java recursion sum

I need a class Person to describe persons. Each person has a name and an array consisting of Person-objects, which represent the person's children. The person class has a method getNumberOfDescendants, which returns an integer equal to the total number of descendants of the person, i.e. his children plus grandchildren plus their children...

How do you sum values inside a for loop in Matlab?

I want to sum acidic as the for loop runs and then print out the total value of all the previous acidic values. My problem is right now is it is currently just printing the individual values not one summed value of acidic. How do I sum. this is what is printing to the command window ans = 5.9676 ans = 2.1676 here is my code pki ...

sql sum or aggregate function on pre-fab column with complex query

I have a query that takes avg data (prices) from 7 days of the week for a long interval. IE avg prices for monday, tues, etc. It works fine, but I'm unsure how I can in the same query sum the avgs that this query finds? Summing Day1..Day5 As it stands this query sums the entire from of all the prices... IE huge number.. not from the ...

Write a function int caluculate_sum(int *a, int size) that calculates the sum of all the elements in an array.

This is what I was given to start with. int main(){ int a[5] = {0,1,2,3,4}; printf("Sum of elements of a: %d\n", calculate_sum(a,5)); return 0; } Here's what I've got, I don't know why it doesn't work, please help me. #include <stdio.h> int main() { int a[5] = {0,1,2,3,4}; int b; ...

Sum contents of column based on a variable with XPath

Hi.. I'm a little bit of a rookie when it comes to XSLT and XPath, so I've run into this problem. I'm creating a simple table based on a view on the databse, which needs to sum some of the columns in the view. What I thourght i could do was add 'SUM_' as a prefix of all the coumns that i want to sum, and cut that tag off with a substring...

How can I sum arrays element-wise in Perl?

Hi. I have two arrays: @arr1 = ( 1, 0, 0, 0, 1 ); @arr2 = ( 1, 1, 0, 1, 1 ); I want to sum items of both arrays to get new one like ( 2, 1, 0, 1, 2 ); Can I do it without looping through arrays? ...

correct approach with t-sql rounding

what's the correct approach in t-sql in the following? : sum(rounded(fractions,2)) or round(sum(of fractions),2) ta! I've tried both approaches and got my total still end up with a different result for each don't know if I need to truncate somwhere I want x, y * @v = z so that sum(x) * @v = sum(z) Thanks ...

Complex date find and inject

I am building a financial reporting app with Ruby on Rails. In the app I have monthly financial statement objects (with 'revenue' as an attribute). For any single financial statement, I want show (1) year-to-date revenue, and (2) last-year-to-date revenue (calendar years are fine). Each object also has a Date (not Datetime) attribute c...

sum of series 1*3-3*5+5*7

please help to print series as well sum of series like 1*3-3*5+5*7 up to n terms i have used code like this in php class series { function ser(){ $i = 0; $k = 3; $m = 0; for($j = 1; $j < 3; $j++) { if($j % 2 == 0 ) { $m = $i + ($i * $k); } else { ...

SQL SUM() function field

I have a database which contains some numerical fields; now i want to create another field which displays the sum of one of these fields. How can I create that field? thanks ...

add extra column value to a column sum

Hi all, I have the following issue: I have a report that uses a Dataset as its datasource. The dataset has two tables, one would be the main table, say Employee, and the second table is EmployeePaycheck, so an employee can have several paychecks. I can compute the sum of a column in the second table, say paycheckValue, but what I can't s...

remove numbers from a list without changing total sum

I have a list of numbers (example: [-1, 1, -4, 5]) and I have to remove numbers from the list without changing the total sum of the list. I want to remove the numbers with biggest absolute value possible, without changing the total, in the example removing [-1, -4, 5] will leave [1] so the sum doesn't change. I wrote the naive approach,...

get max from table where sum required

Suppose I have a table with following data: gameId difficultyLevel numberOfQuestions -------------------------------------------- 1 1 2 1 2 2 1 3 1 In this example the game is configured for 5 questions, but I'm looking for a SQL statement that will work f...

LINQ to SQL sum of decimal values

I can't figure out how to do a simple sum of decimal values. Table<StaffTime> times = ctx.GetTable<StaffTime>(); var query = from t in times select new { t.Hours.Sum() } Isn't Sum an extension method? What am I missing? Bob ...

Add total to group.

I have a Order Details table. What I want to do is create 1 query to show OrderNumber | SKU | QTY | Price | Line Total | 1 SKU1 1 10.00 10.00 1 ---- 0 0.00 10.00 2 SKU1 2 10.00 20.00 2 SKU2 3 1.50 4.50 2 ---- 0 0.00 ...

Subset Sum TI Basic Programming

I'm trying to program my TI-83 to do a subset sum search. So, given a list of length N, I want to find all lists of given length L, that sum to a given value V. This is a little bit different than the regular subset sum problem because I am only searching for subsets of given lengths, not all lengths, and recursion is not necessarily th...

mysql pivot to a postgres pivot table...

I was using mysql just fine until I recently switched one of my rails apps to heroku and had to change over. Almost everything works as expected except I have one query which does something totally funky. This is the postgres, but under mysql it is mostly identical except for the EXTRACT DOW and some group by additions, but that isn't ...

In C# problem grouping by value and then summing

I am trying to sum the cost for a series of items grouped by a person's organization. I believe the summation is working correctly but I am not seeing my grouping. The objects stored in rollup just contain the value of the summation. I'd expect them to have the organization in addition to the sum of the cost for that organization. What h...