Tutorial by Examples: aggregate

Generating a new object in each step: var elements = new[] {1,2,3,4,5}; var commaSeparatedElements = elements.Aggregate( seed: "", func: (aggregate, element) => $"{aggregate}{element},"); Console.WriteLine(commaSeparatedElements); //1,2,3,4,5, Using th...
var letters = "letters".ToCharArray(); char letter = letters[1]; Console.WriteLine("Second Letter is {0}",letter); //in the above example we take the second character from the array //by calling letters[1] //NB: Array Indexing starts at 0; i.e. the first letter would be give...
Unlike the WHERE clause, HAVING can be used with aggregate functions. An aggregate function is a function where the values of multiple rows are grouped together as input on certain criteria to form a single value of more significant meaning or measurement (Wikipedia). Common aggregate function...
Aggregate Applies an accumulator function over a sequence. int[] intList = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int sum = intList.Aggregate((prevSum, current) => prevSum + current); // sum = 55 At the first step prevSum = 1 At the second prevSum = prevSum(at the first step) + 2 At the i-t...
Average The AVG() aggregate function will return the average of values selected. SELECT AVG(Salary) FROM Employees Aggregate functions can also be combined with the where clause. SELECT AVG(Salary) FROM Employees where DepartmentId = 1 Aggregate functions can also be combined with group by ...
Who says you cannot throw multiple exceptions in one method. If you are not used to playing around with AggregateExceptions you may be tempted to create your own data-structure to represent many things going wrong. There are of course were another data-structure that is not an exception would be mor...
The List.fold_left and List.fold_right functions are higher-order functions that implement the outer logic of list aggregation. Aggregating a list, sometimes also referred to as reducing a list, means computing a value derived from the sequential inspection of all items in that list. The documenta...
Counting rows based on a specific column value: SELECT category, COUNT(*) AS item_count FROM item GROUP BY category; Getting average income by department: SELECT department, AVG(income) FROM employees GROUP BY department; The important thing is to select only columns specified in the GRO...
DECLARE @ID AS INT; SET @ID = (SELECT MIN(ID) from TABLE); WHILE @ID IS NOT NULL BEGIN PRINT @ID; SET @ID = (SELECT MIN(ID) FROM TABLE WHERE ID > @ID); END
Aggregation is used to perform complex data search operations in the mongo query which can't be done in normal "find" query. Create some dummy data: db.employees.insert({"name":"Adma","dept":"Admin","languages":["german","f...
Table ORDERS +---------+------------+----------+-------+--------+ | orderid | customerid | customer | total | items | +---------+------------+----------+-------+--------+ | 1 | 1 | Bob | 1300 | 10 | | 2 | 3 | Fred | 500 | 2 | | 3 | ...

Page 1 of 1