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
3 answers

SQL query by date

MySql 5.5. I have a table that represents a work assignment: empId jobNo workDate hours 4 441 10/1/2012 10 4 441 9/1/2012 22 4 441 8/1/2012 6 And one that represents salary: empId …
Reilly
  • 826
  • 9
  • 18
2
votes
0 answers

Map reduce later or calculate at write time?

In my current project we have written some map reduce jobs which in some cases could have been calculated at the point that relevant data was changed. I'm curious as to whether there are some well accepted rules of thumb with regard to the cheapest…
barrymac
  • 2,750
  • 1
  • 20
  • 32
2
votes
4 answers

Problems with Postgresql CASE syntax

Here is my SQL query: SELECT (CASE (elapsed_time_from_first_login IS NULL) WHEN true THEN 0 ELSE elapsed_time_from_first_login END) FROM ( SELECT (now()::ABSTIME::INT4 -…
artaxerxe
  • 6,281
  • 21
  • 68
  • 106
2
votes
0 answers

Incorrect syntax in SQL script when I try to run it on the server

I have this SQL script that I need to run. It creates an aggregate that I need. CREATE AGGREGATE [dbo].[MLRXYZ] (@x1 [float], @x2 [float], @x3 [float], @x4 [float]) RETURNS [xml] EXTERNAL NAME [dws.MultipleLinearRegression].[dws.MLRXYZ] When I…
Y2theZ
  • 10,162
  • 38
  • 131
  • 200
2
votes
1 answer

LINQ to SQL - calling built-in aggregate functions (i.e. STDEV)

Is there any way to have LINQ translate queries directly to functions like SQL's STDEV? For example, the LINQ from t in table group t by t.something into g select new { avg = g.Average(o => o.number) stdev = g.????? } gets turned into a SQL…
Andrew Mao
  • 35,740
  • 23
  • 143
  • 224
2
votes
2 answers

Get ordinality of a row in an ordered result set

I have a collection of manifest records stored in a MySQL database. The schema is as follows: CREATE TABLE `manifests` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `carrier_id` INT(10) UNSIGNED NOT NULL COMMENT 'The carrier for which…
GordonM
  • 31,179
  • 15
  • 87
  • 129
2
votes
2 answers

COUNT, GROUP BY, INNER JOIN, php, mysql

I am currently (trying to) develop a forum. Now I've run into a small obstacle. I've four tables in my database; "categories", "forums", "topics" and "replies". They all have an id, a parent id and a name. My problem is now how I should store and…
Emz
  • 1,280
  • 1
  • 14
  • 29
2
votes
1 answer

Must group to Aggregate?

Is it a requirement that you have to group by something in your select if aggregating such as using SUM? That you must have a group by clause?
PositiveGuy
  • 46,620
  • 110
  • 305
  • 471
2
votes
3 answers

Getting MAX of multiple AVG grouped by another column

I have a query that's used in a bowling center to sort all the best averages in descending order. Everything works well, except that if a player plays in two different leagues (or when I don't group by season since the averages reset after each…
Jumbala
  • 4,764
  • 9
  • 45
  • 65
2
votes
3 answers

C# SQL Aggregate ExecuteScalar Return Query

An SQL aggregate function counting number of name enteries in DB. string cnnStr = ConfigurationManager.ConnectionStrings["LGFConnectionString"].ConnectionString; string mySQL = "SELECT COUNT(*) FROM " + which.table + " WHERE " + which.column + " =…
deDogs
  • 739
  • 1
  • 8
  • 24
2
votes
3 answers

Basic SQL Select statement - How Do I find the Sum?

I want to find the sum and count of specific values in my table. In my specific situation, the table is called product. The column names for the table are 'id, product_id, quantity and shipping_price. The table contains: (Based on SELECT * FROM…
Verdo
  • 25
  • 1
  • 6
2
votes
1 answer

Linq to Objects - Left Outer Join Distinct Object Property Values to an Aggregate Count

Lets say I have a generic list of the the following objects: public class Supermarket { public string Brand { get; set; } public string Suburb { get; set; } public string State { get; set; } public string Country { get; set; } } So…
dcarson
  • 2,853
  • 1
  • 25
  • 34
2
votes
1 answer

Sum total points for multiple tables in MySQL

I'd like to find the sum of a column in a single query given joins between multiple tables. I have a table of Activities, and a table that maps Users performing an Activity, as well as a table mapping Teams to performed Activities. Both Users and…
Mathew Byrne
  • 3,713
  • 5
  • 25
  • 23
2
votes
2 answers

Can SQL SUM() function take an expression as argument?

I'm using SQLite database and I'm wondering whether I'm allowed to write queries as follows: SELECT SUM(column1 * column2) FROM my_table; I googled but references say that SUM function is has the following format: SUM([DISTINCT|ALL] column) And my…
tonytony
  • 1,994
  • 3
  • 20
  • 27
2
votes
2 answers

MySQL SUM() with COUNT() on Multiple Columns

I'm pretty new to MySQL, still trying to learn the ropes. Forgive me if this is too basic I have 3 tables: Student: Student id|Student name| Gender|Parent id Parent: Parent id|Parent name|Parent Address|Parent Phone| and Classes: Class id|Class…
user1361276
  • 99
  • 2
  • 10
1 2 3
99
100