• home
  • forum
  • my
  • kt
  • download
  • How to Use sql Aggregate Functions

    Author: 2008-09-12 10:44:51 From:

    Aggregate means a whole, the term is most used in economics (if you have ever taken an economics class, you probably remember how painful it was :)), it basically means ‘as a whole’. So, we’ll cover a few simple aggregate functions , avg,max, and min.

    Remember the price we concatenated with a string? What if we wanted to see the average price of all our the products in our products table?

    SELECT AVG(price) AS average_price FROM products;

    the query would return something along the lines of 23.94443, obviously depending the prices in your table , if it were cars, it might be 23,232.2238576.

    Notice we also used an alias in there.

    Now , what if we wanted to find the minimum and maximum price in our products table?

    SELECT MIN(price) AS mini_price, MAX(price) AS max_price FROM products;

    The output should be two numbers let’s say : $3.99 $599.99

    That’s it, aggregate functions are often overlooked as an easy way to get quick info.

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Miscellaneous (14)

    New

    Hot