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
1 answer

how to apply having, group by clause while using join for MySQL table

I have 2 tables in MySQL - Question Table QuestionID | QuestionName -----------|--------------------------------------- 1 | How is your faculty communication -----------|--------------------------------------- 2 | How is your…
cbsecommerce
  • 47
  • 1
  • 6
2
votes
2 answers

Conditional time-series data aggregation

I have a relational DB (postgres) with a table that holds time-series metrics. Each row is comprised of - obj_id, metric_id, timestamp, value Let's assume I have 3 metrics of interest with codes - 1, 4 ,5. I would like to filter out all the objects…
Avi
  • 21,182
  • 26
  • 82
  • 121
2
votes
1 answer

PostgreSQL: out of memory issues with array_agg() on a heroku db server

I'm stuck with a (Postgres 9.4.6) query that a) is using too much memory (most likely due to array_agg()) and also does not return exactly what I need, making post-processing necessary. Any input (especially regarding memory consumption) is highly…
maia
  • 116
  • 10
2
votes
2 answers

How to calculate highscores from SQL table?

Ok, I have two MYSQL tables: CREATE TABLE `sessions` ( `id` int(11) NOT NULL AUTO_INCREMENT, `userID` int(11) NOT NULL, `runTime` int(11) NOT NULL, `monstersKilled` int(11) NOT NULL, `profit` int(11) NOT NULL, `tasks` int(11) NOT NULL, …
Cody Butz
  • 294
  • 4
  • 15
2
votes
6 answers

T-SQL Select MAX from subquery

I've got the following tables in a database. We have Product which have multiple Products for a Series, and we have ProductVariation which has multiple product variations per product. We are wishing to perform a set of aggregate queries on the…
Mike Upjohn
  • 1,251
  • 2
  • 16
  • 38
2
votes
2 answers

SQL query to get single row value from an aggregate

I have an Oracle table with two columns ID and START_DATE, I want to run a query to get the ID of the record with the most recent date, initially i wrote this: select id from (select * from mytable order by start_date desc) where rownum = 1 Is…
wsb3383
  • 3,841
  • 12
  • 44
  • 59
2
votes
1 answer

MySQL count changes

I would like to count number of changes in column Value grouped by Id using MySQL. Source Table: create table sequence ( `Id` int, `Date` date, `Value` int not null, PRIMARY KEY (`Id`,`Date`) ); insert into sequence ( `Id`,`Date`,…
Krivers
  • 1,986
  • 2
  • 22
  • 45
2
votes
2 answers

PostgreSQL: How to select last balance for each account on each day in a given date range?

I am running PostgreSQL 9.3 and have a table that looks something like this: entry_date | account_id | balance ---------------------+------------+--------- 2016-02-01 00:00:00 | 123 | 100 2016-02-01 06:00:00 | 123 | …
Shaun Scovil
  • 3,905
  • 5
  • 39
  • 58
2
votes
2 answers

Using LINQ to SQL group, sum and aggreate all together

I have two tables Students and Origami. Origami has Foreign Key of Students table. Each student can make one or more origami for each month. Students sample data: StudentId, FirstName, LastName 187 , John , Maslow 196 , Crystal , Hood 195 , Sarah…
Narazana
  • 1,940
  • 15
  • 57
  • 88
2
votes
3 answers

switch between aggregate functions with linq

I have two methods that look almost the same, except for the aggregate function used in the Linq query. For example: public IEnumerable DoStuff(IEnumerable someItems) { var items = someItems.GroupBy(i => i.Date).Select(p => new…
Fernando
  • 4,029
  • 1
  • 26
  • 35
2
votes
2 answers

JOIN, aggregate and convert in postgres between two tables

Here are the two tables i have: [all columns in both tables are of type "text"], Table name and the column names are in bold fonts. Names -------------------------------- Name | DoB | Team | -------------------------------- Harry | …
2
votes
3 answers

POSTGRES min/least value

I have a postgres 9.3 table with two columns. The first column has times and the second has routes. A route may have multiple times. I want to list all routes with their most minimum times. My table: Times Routes 07:15:00 Route a 09:15:00 …
Ang
  • 153
  • 1
  • 2
  • 9
2
votes
2 answers

Oracle - Pivot Aggregate function results

I have table where user daily activities are saved, and now I have to present these activities in report in following form. I have written a query, select ua.UserID, count(ua.UserID), (select count(*) form user_activities t1 where t1.UserID =…
user3141985
  • 1,395
  • 4
  • 17
  • 36
2
votes
3 answers

MAX function used with GROUP BY clause

I have database with name, salary and department of employees. I need a query for getting employee(s) with highest salaries in each department. Database: create table test( employee_name VARCHAR(255), department VARCHAR(255), salary INT …
JRr
  • 1,552
  • 1
  • 19
  • 23
2
votes
3 answers

Convert Postgres Aggregate Function to Inline Array

I've been asked how to do a standard deviation on a variable list of values within a row. For example: select name, x, y, z, stddev (x, y, z) from foo; or select order_no, a, b, c, d, e, f, stddev (a, b, c, d, e, f) from foo; So essentially…
Hambone
  • 15,600
  • 8
  • 46
  • 69