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

Hide MySQL count column

When you use count and group by in mysql, how do I hide the count column that implicitly shows up in the resulting table? SELECT name, region, COUNT(*) as num_visits FROM world GROUP BY region HAVING num_visits > 1 This will display a…
user1530318
  • 25,507
  • 15
  • 37
  • 48
2
votes
1 answer

UPDATE based on Aggregation - T/SQL

CREATE TABLE #Table1 ( ID INT Identity (1,1), Col1 varchar(10), Col2 DateTime2(7), Col3 INT, COl4 INT ); INSERT INTO #Table1 VALUES ('Part1','2014-01-23 22:00:00.0000000', NULL, NULL), ('Part2','2014-01-23 23:00:00.0000000', NULL,…
007
  • 2,136
  • 4
  • 26
  • 46
2
votes
1 answer

Cassandra efficient table walk

I'm currently working on a benchmark (which is part of my bachelor thesis) that compares SQL and NoSQL Databases based on an abstract data model an abstract queries to achieve fair implementation on all systems. I'm currently working on the…
hoffmax91
  • 131
  • 1
  • 10
2
votes
2 answers

Select subarray and its length in PostgreSQL

How can I get subquery array and it`s count? SELECT location.country, (SELECT array( SELECT competition.id FROM competition WHERE location.id = competition.location_id )) AS list, …
Vladimir Nani
  • 2,774
  • 6
  • 31
  • 52
2
votes
2 answers

SQLite: Multiple aggregate columns

I'm a little new to SQL world and still learning the ins and outs of the language. I have a table with an id, dayOfWeek, and a count for each day. So any given id might appear in the table up to seven times, with a count of events for each day for…
Andrew LaPrise
  • 3,373
  • 4
  • 32
  • 50
2
votes
0 answers

How to select MAX along with another column in SQL

Lets say I have the table as follows Name Firm Salary Aron X 100 Bill X 200 Clint Y 300 I want to find the firm with maximum number of employees and produce the result Firm Total X 2 However here is my problem,…
user3041058
  • 1,520
  • 2
  • 12
  • 16
2
votes
2 answers

Use mysql SUM() and generate a random number in a WHERE clause

Suppose I have this table : +------------------------------------+ | T_BOULEVERSEMENT | +---------------------+--------------+ | PK_A_BOULEVERSEMENT | I_OCCURRENCE | +---------------------+--------------+ | 1 | …
Loïc G.
  • 3,087
  • 3
  • 24
  • 36
2
votes
3 answers

SSRS Report Total is incorrect

I want total of debit from invoice table and credit from payment table. credit total display correctly while debit is incorrect. I use Group on invoice# invoice table field. It seems that it sum twice a value. Can anyone tell me where i am…
riaz.usmani
  • 271
  • 1
  • 4
  • 13
2
votes
2 answers

tableau aggregate data based on dimension

I am having a problem in Tableau, hopefully someone can help me and is very much appreciated!! A simplifiend example of a problem I can't fix in Tableau: Payment Customer Amount 1 BMW 20000 2 VW 30000 3 BMW…
Tim_Utrecht
  • 1,459
  • 6
  • 24
  • 44
2
votes
3 answers

aggregation in Tsql

I have this sql query: select ct.ID, t.Tag from links ct inner join tags t on ct.ID_TAG = t.ID_TAG returning this resultset: ID |…
2
votes
1 answer

How can I concatenate strings in a GROUP BY clause without a subquery in SQL Server without an additional query?

I'm looking for the equivalent of a GROUP_CONCAT() MySQL function in SQL Server 2012 - THAT DOES NOT USE A SUBQUERY, explained below: CREATE TABLE Temp ( ID INT PRIMARY KEY NOT NULL IDENTITY(1,1), ColA varchar(900) NULL, ColB varchar(900)…
Ehryk
  • 1,930
  • 2
  • 27
  • 47
2
votes
3 answers

PostgreSQL sum typecasting as a bigint

I am doing the sum() of an integer column and I want to typecast the result to be a bigint - to avoid an error. However when I try to use sum(myvalue)::bigint it still gives me an out of range error. Is there anything that I can do to the query to…
Aaron Kreider
  • 1,705
  • 5
  • 22
  • 44
2
votes
4 answers

Unique aggregate function when singular value is guaranteed by the WHERE clause

Given the following: CREATE TABLE A (A1 INTEGER, A2 INTEGER, A3 INTEGER); INSERT INTO A(A1, A2, A3) VALUES (1, 1, 1); INSERT INTO A(A1, A2, A3) VALUES (2, 1, 1); I want to select the maximum A1 given specific A2 and A3 values, and have those…
Marcus Junius Brutus
  • 26,087
  • 41
  • 189
  • 331
2
votes
1 answer

Select SUM of rows with different WHERE condition per column

Either this is just not a good idea or it's so elementary that I'm not finding it. Suppose I have a table like: User | Q1 | Q2 | Q3 ann | 3 | 2 | 5 joe | 1 | 4 | 4 joe | 5 | 2 | 2 ann | 4 | 4 | 4 What I would…
Anthony
  • 36,459
  • 25
  • 97
  • 163
2
votes
3 answers

Why does the following join increase the query time significantly?

I have a star schema here and I am querying the fact table and would like to join one very small dimension table. I can't really explain the following: EXPLAIN ANALYZE SELECT COUNT(impression_id), imp.os_id FROM bi.impressions imp GROUP BY…
Istvan
  • 7,500
  • 9
  • 59
  • 109