Questions tagged [sum]

The result of adding two or more quantities together.

sum
Filter by
Sorted by
Tagged with
16 votes
2 answers
107k views

TSQL Cast the sum as Money

Using SQL Server 2008, I am trying to get the return of some of these columns to come back as $xxx,xxx.xx This is the query that I am using (this query then some updates just to calculate the numbers ...
JohnZ's user avatar
  • 482
16 votes
1 answer
20k views

'System.Collections.Generic.List<float>' does not contain a definition for 'Sum'

I am trying to Sum a list of floats with built in Sum() function but I keep getting this error : Error CS1061: 'System.Collections.Generic.List' does not contain a definition for 'Sum' and no ...
Patryk's user avatar
  • 23.4k
16 votes
1 answer
48k views

GROUP and SUM in Entity Framework

I want to select sum of all (paid) prices of an order item for each customer. Here is SQL command: SELECT c.name,SUM(oi.price * oi.count) from customer c JOIN order o ON c.id=o.customer_id JOIN ...
quin16's user avatar
  • 515
16 votes
4 answers
36k views

How can I sum columns across multiple tables in MySQL?

In MySQL I have two tables: Table MC: ---------------- |TransNo | Qty | |--------|-----| | xxx1 | 4 | | xxx3 | 3 | and Table Amex: ---------------- |TransNo | Qty | |---------|-----| | ...
phpJs's user avatar
  • 452
16 votes
5 answers
3k views

Avoiding Python sum default start arg behavior

I am working with a Python object that implements __add__, but does not subclass int. MyObj1 + MyObj2 works fine, but sum([MyObj1, MyObj2]) led to a TypeError, becausesum() first attempts 0 + MyObj. ...
Lenna's user avatar
  • 1,445
16 votes
3 answers
38k views

MYSQL - Using SUM with JOIN

Ok, so I have 4 tables. A users table with columns id and name. A groups table with columns id, name and owner. A items table with columns group and content. A content table with columns id, name ...
Jimmery's user avatar
  • 9,963
16 votes
5 answers
10k views

How to make a linq Sum return null if the summed values are all null

I have a LINQ query that looks like this... var duration = Level3Data.AsQueryable().Sum(d => d.DurationMonths); If all the d.DurationMonths values are null the Sum returns 0. How can I make the ...
Simon Keep's user avatar
  • 9,944
16 votes
7 answers
19k views

Surpassing MySQL's TIME value limit of 838:59:59

The title might be a bit confusing so allow me to explain. I'm using a table to record my work logs. Every day I'll create an entry stating from what time to what time I have worked and I'll add a ...
Wesley's user avatar
  • 311
15 votes
2 answers
51k views

MySQL SUM of a COUNT with GROUP BY clause

I wish to SUM the COUNT of a query as follows. This query returns the count properly (1) for each row, but not sure how to add them all up. SELECT COUNT(*), jss_orders_headers.* FROM ...
Jeepstone's user avatar
  • 2,601
15 votes
3 answers
82k views

SQL select all records only if the sum is greater than 100

I'm not exactly sure how to ask this so I'll give an example I have a huge table that resembles something like this... Name Widgets TransDate Location Abby 2 12/1/2010 Middleton Abby 13 ...
user1144191's user avatar
15 votes
3 answers
9k views

Python equivalent of sum() using xor()

I like the Python sum function : >>> z = [1] * 11 >>> zsum = sum(z) >>> zsum == 11 True I want the same functionality with using xor (^) not add (+). I want to use map. ...
Cris Stringfellow's user avatar
15 votes
8 answers
20k views

SELECT SUM returns a row when there are no records

I'm finding some problems with a query that returns the sum of a field from a table for all the records that meet certain conditions. I expected to receive a "No records found' when there were no ...
Jose L Martinez-Avial's user avatar
15 votes
3 answers
39k views

What is a subtraction function that is similar to sum() for subtracting items in list?

I am trying to create a calculator, but I am having trouble writing a function that will subtract numbers from a list. For example: class Calculator(object): def __init__(self, args): ...
user1306134's user avatar
15 votes
2 answers
59k views

To calculate sum() two alias named columns - in sql

To calculate sum() of two temp column names declared in query - in SQL stud table has only two columns m1,m2. total and total1 is given as temp name. select m1, m2, SUM(m1) + SUM(m2) as ...
Innova's user avatar
  • 4,901
15 votes
2 answers
77k views

SUM total time in SQL Server [duplicate]

I have a problem with the SUM operator in SQL Server. When I write this query: SELECT StudentID, StudentName, SUM(time) as 'TotalTime' FROM WorkNote GROUP BY StudentID, StudentName I get this error:...
Anna Dino 's user avatar
15 votes
1 answer
15k views

pandas rolling sum of last five minutes

Assume I have below data frame Date, A 2014-11-21 11:00:00, 1 2014-11-21 11:03:00, 4 2014-11-21 11:04:00, 1 2014-11-21 11:05:00, 2 2014-11-21 11:07:00, 4 2014-11-21 11:08:00, 1 2014-11-21 11:12:00, 1 ...
Sajith Edirisinghe's user avatar
15 votes
1 answer
6k views

parallel prefix (cumulative) sum with SSE

I'm looking for some advice on how to do a parallel prefix sum with SSE. I'm interested in doing this on an array of ints, floats, or doubles. I have come up with two solutions. A special case and ...
Z boson's user avatar
  • 33.1k
15 votes
2 answers
19k views

Linq Query with SUM and ORDER BY

I have a (C#) class called Hit with an ItemID (int) and a Score (int) property. I skip the rest of the details to keep it short. Now in my code, I have a huge List on which I need to do the following ...
Mats's user avatar
  • 15.1k
15 votes
2 answers
5k views

Minimum of sum of absolute values

Problem statement: There are 3 arrays A,B,C all filled with positive integers, and all the three arrays are of the same size. Find min(|a-b|+|b-c|+|c-a|) where a is in A, b is in B, c is in C. I ...
wsdookadr's user avatar
  • 2,612
15 votes
3 answers
7k views

Incorrect decimals appearing in SUM MySQL

I have the following SQL query. SELECT SUM(final_insurance_total) as total FROM `leads` GROUP BY leads.status I have a single row of data in the lead table with a value for final_insurance_total of ...
Ben's user avatar
  • 387
14 votes
9 answers
19k views

How can I sum arrays element-wise in Perl?

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?
Dmytro Leonenko's user avatar
14 votes
2 answers
14k views

sum of N lists element-wise python

Is there an easy way to compute the element-wise sum of N lists in python? I know if we have n lists defined (call the ith list c_i), we can do: z = [sum(x) for x in zip(c_1, c_2, ...)] For example: ...
user avatar
14 votes
3 answers
50k views

Running total by grouped records in table

I have a table like this (Oracle, 10) Account Bookdate Amount 1 20080101 100 1 20080102 101 2 20080102 200 1 20080103 -200 .....
Zsolt Botykai's user avatar
14 votes
8 answers
11k views

sum of small double numbers c++

Assume that we have an array of small (about 10^(-15) ) double numbers in c++. If we calculate the sum of numbers in this array sequentially, for example double sum = 0; for (int i = 0; i < n; i++...
Nurlan's user avatar
  • 2,910
14 votes
2 answers
40k views

Conditional SUM on oracle SQL

I have the data in the follow way: ITEM LOCATION UNIT RETAIL QUANTITY 100 KS 10 -10 200 KS 20 30 I want the sum of positive quantities (quantity > 0) ...
Imran Hemani's user avatar
14 votes
11 answers
12k views

Finding minimal absolute sum of a subarray

There's an array A containing (positive and negative) integers. Find a (contiguous) subarray whose elements' absolute sum is minimal, e.g.: A = [2, -4, 6, -3, 9] |(−4) + 6 + (−3)| = 1 <- minimal ...
NPS's user avatar
  • 6,133
14 votes
3 answers
13k views

How to sum fields of collection elements without mapping them first (like foldLeft/reduceLeft)?

Consider this class: case class Person(val firstName: String, val lastName: String, age: Int) val persons = Person("Jane", "Doe", 42) :: Person("John", "Doe", 45) :: Person("Joe", "...
soc's user avatar
  • 28.2k
14 votes
3 answers
52k views

How to sum in pandas by unique index in several columns?

I have a pandas DataFrame which details online activities in terms of "clicks" during an user session. There are as many as 50,000 unique users, and the dataframe has around 1.5 million samples. ...
ShanZhengYang's user avatar
14 votes
3 answers
17k views

Python Data Frame: cumulative sum of column until condition is reached and return the index

I am new in Python and am currently facing an issue I can't solve. I really hope you can help me out. English is not my native languge so I am sorry if I am not able to express myself properly. Say I ...
AMaz's user avatar
  • 181
14 votes
3 answers
4k views

Why is the sum of an empty set null?

If I do: int updateGamePlays = db.tblArcadeGames.Where(c => c.ParentGameID == GameID).Sum(c => c.Plays); If no records are returned in this query it throws: System.InvalidOperationException:...
Tom Gullen's user avatar
13 votes
5 answers
73k views

LINQ-to-SQL - 'Sum' inside a select new

I have a LINQ-to-SQL query that runs through a table, that I want to select 3 sum's - the sums of 'Rate' and 'AdditionalCharges', so I have something like this: var sums = from d in dc.Deliveries ...
Chris's user avatar
  • 7,571
13 votes
6 answers
35k views

How to sum N number of time (HH:MM Format)?

I am using the following sample code to calculate sum of two different time values. Now I want to get the sum of N number of time values. // numbers for testing $o="12:59"; $p="0:58"; // display for ...
user3239311's user avatar
13 votes
10 answers
68k views

Sum of digits in a string

if i just read my sum_digits function here, it makes sense in my head but it seems to be producing wrong results. Any tip? def is_a_digit(s): ''' (str) -> bool Precondition: len(s) == 1 Return ...
user1864828's user avatar
13 votes
3 answers
21k views

Column sum of Opencv Matrix elements

I need to compute sum of elements in all columns separately. Now I'm using: Matrix cross_corr should be summed. Mat cross_corr_summed; for (int i=0;i<cross_corr.cols;i++) ...
Robert Kirchhoff's user avatar
13 votes
6 answers
26k views

R - min, max and mean of off-diagonal elements in a matrix

I have like a matrix in R and I want to get: Max off - diagonal elements Min off – diagonal elements Mean off –diagonal elements With diagonal I used max(diag(A)) , min(diag(A)) , mean(diag(A)) and ...
amhemad ahmad's user avatar
13 votes
6 answers
15k views

How to sum a list of tuples

Given the following list of tuples... val list = List((1, 2), (1, 2), (1, 2)) ... how do I sum all the values and obtain a single tuple like this? (3, 6)
j3d's user avatar
  • 9,638
13 votes
2 answers
10k views

Get the sum of multiple columns

I have three columns, which I am trying to get the sum of each one returned. I can do it for one column: var data = db.Test.Sum(x => x.Column1); I can't figure out how to get the sum for three ...
Joseph's user avatar
  • 2,716
13 votes
5 answers
35k views

Sum by distinct column value in R

I have a very large dataframe in R and would like to sum two columns for every distinct value in other columns, for example say we had data of a dataframe of transactions in various shops over a day ...
user1165199's user avatar
  • 6,551
13 votes
7 answers
6k views

calculate sum of each td having similar class

My html table td looks like this <td class="20">1</td> <td class="20">2</td> <td class="20">3</td> <td class="20">4</td> <td class="20">5</td&...
Matarishvan's user avatar
  • 2,432
13 votes
2 answers
41k views

SUM of only TOP 10 rows

I have a query where I am only selecting the TOP 10 rows, but I have a SUM function in there that is still taking the sum of all the rows (disregarding the TOP 10). How do I get the total of only the ...
Cfw412's user avatar
  • 131
13 votes
3 answers
4k views

PHP is confused when adding and concatenating

I have the following code: <?php $a = 1; $b = 2; echo "sum: " . $a + $b; echo "sum: " . ($a + $b); ?> When I execute my code I get: 2 sum: 3 Why does it fail to print the ...
aizquier's user avatar
  • 567
13 votes
6 answers
21k views

Python how to reduce multiple lists?

I am able to use map and sum to achieve this functionality, but how to use reduce? There are 2 lists: a, b, they have same number of values. I want to calculate a[0]*b[0]+a[1]*b[1]+...+a[n]*b[n] ...
zs2020's user avatar
  • 54.1k
13 votes
4 answers
26k views

Sum rows where value equal in column

How can I sum across rows that have equal values in the first column of a numpy array? For example: In: np.array([[1,2,3], [1,4,6], [2,3,5], [2,6,2], ...
user998476's user avatar
13 votes
3 answers
8k views

Generate all possible lists of length N that sum to S in Python

I'm trying to generate all possible lists of Length N that sum to S. I've written some code to do so, but on anything large (in particular, I want N=5, S=100), I run into memory overflow errors. I'm ...
Nick2253's user avatar
  • 339
13 votes
2 answers
7k views

sum of two lists with lists in R

Is there an easy way to do a simple calculation in a list of lists? x <- list(a=list(1:4),b=list(1:6)) y <- list(a=list(1:4),b=list(1:6)) When I try: x+y I receive the error: Error in x + y :...
Jetse's user avatar
  • 1,746
13 votes
3 answers
8k views

MySQL - Sum only if all rows are not null, else return null

Let's suppose the following table: X VALUE 1 2 1 3 2 NULL 2 4 I want a result set grouped by X with the sum of VALUE, but only if all the rows related to each X value are not null. ...
user3418803's user avatar
13 votes
3 answers
20k views

SQLite: accumulator (sum) column in a SELECT statement

I have a table like this one: SELECT value FROM table; value 1 3 13 1 5 I would like to add an accumulator column, so that I have this result: value accumulated 1 1 3 4 13 17 1 ...
moala's user avatar
  • 5,184
13 votes
3 answers
9k views

LINQ Sum OverflowException?

I've implemented a custom IEqualityComparer for EventLogEntry. public class EventLogEntryListComparison : IEqualityComparer<List<EventLogEntry>>, IEqualityComparer<...
M Afifi's user avatar
  • 4,725
13 votes
1 answer
551 views

Why is the Linq-to-Objects sum of a sequence of nullables itself nullable?

As usual, int? means System.Nullable<int> (or System.Nullable`1[System.Int32]). Suppose you have an in-memory IEnumerable<int?> (such as a List<int?> for example), let us call it ...
Jeppe Stig Nielsen's user avatar
12 votes
6 answers
116k views

What are the ways to sum matrix elements in MATLAB?

Given the matrix: A = [1 2 3; 4 5 6; 7 8 9]; How could you use a for loop to compute the sum of the elements in the matrix? Write a one line MATLAB command using the function sum to sum the matrix ...
izzat's user avatar
  • 519