sum

SQL Server 2012: sum over order by gives error Incorrect syntax near 'order'

断了今生、忘了曾经 提交于 2021-02-07 22:39:36
问题 declare @t table (cid int, amount int, cname varchar) insert into @t values (6, 20, 'C'), (7, 30, 'C'), (8, 10, 'C'), (9, 10, 'D') select sum(amount) over (partition by cname order by cid), * from @t Throws an error: Incorrect syntax near 'order'. https://msdn.microsoft.com/en-us/library/ms187810.aspx Isn't sum over order by supported in SQL Server 2012? If I remove order by and use only partition by it works but for 'C' I get 60 for all rows. I want to get running total. More info: Microsoft

SQL Server 2012: sum over order by gives error Incorrect syntax near 'order'

僤鯓⒐⒋嵵緔 提交于 2021-02-07 22:38:58
问题 declare @t table (cid int, amount int, cname varchar) insert into @t values (6, 20, 'C'), (7, 30, 'C'), (8, 10, 'C'), (9, 10, 'D') select sum(amount) over (partition by cname order by cid), * from @t Throws an error: Incorrect syntax near 'order'. https://msdn.microsoft.com/en-us/library/ms187810.aspx Isn't sum over order by supported in SQL Server 2012? If I remove order by and use only partition by it works but for 'C' I get 60 for all rows. I want to get running total. More info: Microsoft

Scipy Sparse Cumsum

谁都会走 提交于 2021-02-07 11:51:47
问题 Suppose I have a scipy.sparse.csr_matrix representing the values below [[0 0 1 2 0 3 0 4] [1 0 0 2 0 3 4 0]] I want to calculate the cumulative sum of non-zero values in-place, which would change the array to: [[0 0 1 3 0 6 0 10] [1 0 0 3 0 6 10 0]] The actual values are not 1, 2, 3, ... The number of non-zero values in each row are unlikely to be the same. How to do this fast? Current program: import scipy.sparse import numpy as np # sparse data a = scipy.sparse.csr_matrix( [[0,0,1,2,0,3,0,4

Aggregating more than two properties Java 8

泪湿孤枕 提交于 2021-02-07 10:59:34
问题 To be very simple I have class Per{ int a; long b; double c; String d; } Let say I have 3000 Object of Type Per and collected in a List<Per> pers Now I want to achieve:- Skip if object is null or d is null or blank sum of a sum of b aggregated value of operation performed on c Old way is int totalA = 0; long totalB = 0l; long totalC = 0l; for (Per per : pers) { if (per.d != null && !per.d.trim().equals("")) { totalA += per.a; totalB += per.b; totalC += someOperation(per.c); } } someOperation

Recursive sum of an array in C [duplicate]

99封情书 提交于 2021-02-07 09:34:20
问题 This question already has answers here : calculate the sum of all element in a double array (12 answers) Closed 7 years ago . Hello I'm learning recursion in C and I am trying to find the sum of the elements. This is my main: int main() { int arr[] = {1,2,3,4,5}; int sum; sum = arr_sum(arr,4); printf("\nsum is:%d",sum); return 0; } And my recursive function: //n is the last index of the array int arr_sum( int arr[], int n ) { // must be recursive int sum = 0; //base case: if (n < 0) { return

Recursive sum of an array in C [duplicate]

守給你的承諾、 提交于 2021-02-07 09:33:59
问题 This question already has answers here : calculate the sum of all element in a double array (12 answers) Closed 7 years ago . Hello I'm learning recursion in C and I am trying to find the sum of the elements. This is my main: int main() { int arr[] = {1,2,3,4,5}; int sum; sum = arr_sum(arr,4); printf("\nsum is:%d",sum); return 0; } And my recursive function: //n is the last index of the array int arr_sum( int arr[], int n ) { // must be recursive int sum = 0; //base case: if (n < 0) { return

Sum of all elements in an array

≡放荡痞女 提交于 2021-02-07 07:50:32
问题 I am a beginner in programming. I want to do the sum of all elements in an array. I made this but I can't see where are my mistakes? function ArrayAdder(_array) { this.sum = 0; this.array = _array || []; } ArrayAdder.prototype.computeTotal = function () { this.sum = 0; this.array.forEach(function (value) { this.sum += value; }); return this.sum; }; var myArray = new ArrayAdder([1, 2, 3]); console.log(myArray.computeTotal()); 回答1: this inside the forEach callback refers to the global window

Google Interview: Find all contiguous subsequence in a given array of integers, whose sum falls in the given range. Can we do better than O(n^2)?

馋奶兔 提交于 2021-02-05 12:42:31
问题 Given an array of Integers, and a range (low, high), find all contiguous subsequence in the array which have sum in the range. Is there a solution better than O(n^2)? I tried a lot but couldn't find a solution that does better than O(n^2). Please help me find a better solution or confirm that this is the best we can do. This is what I have right now, I'm assuming the range to be defined as [lo, hi] . public static int numOfCombinations(final int[] data, final int lo, final int hi, int beg,

Google Interview: Find all contiguous subsequence in a given array of integers, whose sum falls in the given range. Can we do better than O(n^2)?

主宰稳场 提交于 2021-02-05 12:42:11
问题 Given an array of Integers, and a range (low, high), find all contiguous subsequence in the array which have sum in the range. Is there a solution better than O(n^2)? I tried a lot but couldn't find a solution that does better than O(n^2). Please help me find a better solution or confirm that this is the best we can do. This is what I have right now, I'm assuming the range to be defined as [lo, hi] . public static int numOfCombinations(final int[] data, final int lo, final int hi, int beg,

Sum arrays in array (JavaScript) [duplicate]

江枫思渺然 提交于 2021-02-05 10:54:25
问题 This question already has answers here : How to find the sum of an array of numbers (45 answers) Merge/flatten an array of arrays (84 answers) Closed 2 years ago . I have an array that consists of multiple arrays: var array = [[1], [2, 1, 1], [3, 4]]; Now I want to get an array that has elements that are the sums of each array in the variable "array". In this example that would be var sum = [1, 4, 7]. How can I do this? 回答1: You can use Array#map to return the new items. The items can be