Questions tagged [aggregate-functions]

Aggregate functions are a subset of SQL functions that compute a single value from multiple input rows, mostly used in `SELECT` queries with a `GROUP BY` clause. Practically all modern RDBMS feature aggregate functions. Typical examples include `COUNT()`, `SUM()`, `MIN()`, `MAX()`, and `AVG()`.

Aggregate functions are a subset of SQL functions that compute a single value from multiple input rows, mostly used in SELECT queries with a GROUP BY clause. Practically all modern RDBMS feature aggregate functions.

Typical examples include COUNT(), SUM(), MIN(), MAX(), and AVG().

5778 questions
2
votes
2 answers

Update a mySQL table when something changes

This may be a stupid question but is it possible to store a count query in a field in a table such that when the result of the count changes the result will update itself? Thread(ThreadID,NumMessages) …
Graeme Smyth
  • 136
  • 5
2
votes
2 answers

SQL aggregation using join

I have 2 tables with Naam as primary key, the one table contains information on Naam (lumchartcentrumuser) and the other table contains information on presentations held by naam (lumchartecentrumonderwijs). I want to use a bit more complex…
Mihaly
  • 303
  • 1
  • 3
  • 14
2
votes
2 answers

How to aggregate NumPy record array (sum, min, max, etc.)?

Consider a simple record array structure: import numpy as np ijv_dtype = [ ('I', 'i'), ('J', 'i'), ('v', 'd'), ] ijv = np.array([ (0, 0, 3.3), (0, 1, 1.1), (0, 1, 4.4), (1, 1, 2.2), ], ijv_dtype) print(ijv) # [(0, 0,…
Mike T
  • 41,085
  • 18
  • 152
  • 203
2
votes
3 answers

aggregate with FUN = 'c' or 'list' in R

Been searching around but with no luck so far. Here is the data frame. > test = data.frame(x = c(1,1,2,2,3,3), y = c('a','b','c','d','e','f')) > test x y 1 1 a 2 1 b 3 2 c 4 2 d 5 3 e 6 3 f Was looking for a way to aggregate such that y with…
user2165
  • 1,951
  • 3
  • 20
  • 39
2
votes
2 answers

How to use array_agg() aggregate function in pig or hive

I have the below data: ================================================================ session_id screen_name screen_launch_time ================================================================ 990004916946605-1404157897784 …
2
votes
4 answers

SQL select column multiple times with different conditions

I have a table with Incidents that contains column for number injured in the incident and column for number killed in that incident. Incident table is linked with Participants table where you can find a column for age of the person and there is…
2
votes
3 answers

Add cumulative total sum over many columns in Postgres

My table is like this: +----+--------+--------+--------+---------+ | id | type | c1 | c2 | c3 | +----+--------+--------+--------+---------+ | a | 0 | 10 | 10 | 10 | | a | 0 | 0 | 10 | | | a |…
2
votes
3 answers

Pandas Dataframe Groupby multiple columns then sum

Assume the following for each Python code: import pandas as pd import numpy as np In Pandas, if I have a dataframe of 2 columns, one of which is an array of numbers, I can sum over the values of the array to get a single array. df =…
lebca
  • 185
  • 2
  • 5
2
votes
1 answer

Linq to sql calculating a percentage of a group of items in query

New to Linq to SQL and novice in SQL. First post so please be gentle. I have something similar to the following table I am querying into a dataGridView based on a date range in C#. HeatNumber ChargeNumber Weight DOB 1 1 …
Xgrunt24
  • 25
  • 1
  • 4
2
votes
1 answer

Return only one element from strings array in elasticsearch

I have array of strings in one field "strArray": strArray: ['browser:IE', 'device:PC', 'country:USA', 'state:CA'] I need do aggregations by browser (device, country or state). It's not a problem, if I know order of these values in strArray field. I…
yAnTar
  • 4,269
  • 9
  • 47
  • 73
2
votes
2 answers

MySQL GROUP BY quantity

MySQL table is like this (VoteID is PK): VoteID VoteValue CommentID 1 -1 1 2 -1 1 3 1 1 4 -1 1 5 1 2 6 1 2 7 -1 2 I need a…
x17az
  • 257
  • 1
  • 4
  • 9
2
votes
2 answers

Mysql return 0 not null in sum

Help needed please I have a table with taskId, Materials, Labour and a table with expenses in. The issue i have is that some tasks do not have and expense column in the taskenpense table so the column returns null. I need null to be 0. `…
jonathan young
  • 237
  • 2
  • 11
2
votes
2 answers

mysql fetch sum php

sql column - trans_value contain both positive and negative value amount. so i'm trying to figure out how do i set a sum of positive value and negative value aside, so that i can calculate the how much sum of positive and how much is sum of…
damien
  • 171
  • 1
  • 4
  • 7
2
votes
1 answer

Postgresql array_agg of multiple columns with JDBC

I'm trying to join a table that might have multiple entries for the given id and aggregate the rows corresponding to this id in an array. This looks as follows in the SQL query: SELECT * from data LEFT JOIN (select id, array_agg(row(foo, bar)) AS…
panmari
  • 3,627
  • 3
  • 28
  • 48
2
votes
0 answers

Join through multiple tables in nHibernate via QueryOver

I have these tables: components, devicehardwareprofiles, componenttemplates, cashrecyclercounters on MsSql database I need to fill this variables: int capacity, loaded by data from this query: select sum(ct.capacity * cc.denomination) as capacity,…