Database Tutorial

Course Tutorial Site

Site Admin

Aggregation

with 5 comments

This is a lesson on basic aggregation in SQL. Aggregation in SQL means counting, adding, and grouping by results of counts or sums. Aggregation is a critical part of using the SQL language. At a basic level, aggregation includes the COUNT, SUM, AVERAGE, MAX, and MIN aggregation functions; and the ORDER BY, GROUP BY, and HAVING clauses.

You’ll find the setup scripts for these examples at the bottom of this blog page. The best way to use this page is to copy the setup code, run it in your database, and then test the examples as you work though them.

Written by michaelmclaughlin

February 24th, 2010 at 12:47 am

Posted in

5 Responses to 'Aggregation'

Subscribe to comments with RSS or TrackBack to 'Aggregation'.

  1. “– Query ordered by the sets and then the integers in ascending order.
    SELECT * FROM ordinal ORDER BY 2, 4;”

    So it orders it by column number 2, and then after ordering column 2, it orders the column 4 values? So if I were to have it as SELECT * FROM ordinal ORDER BY 4, 2; would it order the numbers, then order the groups? I don’t know if my question makes sense.

    Aaron Haggen

    26 Feb 10 at 2:39 pm

  2. Yes, it makes sense, and yes that’s the point.

    michaelmclaughlin

    26 Feb 10 at 10:02 pm

  3. Under the Dateset near Min and Max:
    “The next section makes the same comparison with the MAX, and MIN functions. The maximum or minimums are the same because they the uniqueness doesn’t change the minimum or maximum of the sets.”

    …maximum or minimums are the same because “they” the…

    I believe the they should be removed, or the sentence should be reworded, for clarity.

    Samuel Terrazas

    1 Nov 10 at 1:13 pm

  4. The next section makes the same comparison with the MAX, and MIN functions. The maximum or minimums are the same because they the uniqueness doesn’t change the minimum or maximum of the sets.

    “because they the” perhaps just ‘the’ is what you meant?

    -Doug

    Doug Kelley

    13 Dec 10 at 12:10 pm

  5. Doug, Finally fixed.

    michaelmclaughlin

    22 Oct 14 at 2:36 am

Leave a Reply