統計函數

MIN 傳回指定欄位最小值
MAX 傳回指定欄位最大值
SUM 傳回指定欄位總和
AVG 傳回指定欄位平均值
COUNT 傳回指定欄位的筆數
COUNT(*) 傳回資料庫中的總筆數

統計函數使用於資料表中的數值欄位配合 SELECT 語法使用。 只用於總結特定單一欄位,可以配合 "GROUP BY" 做篩選,但也可以不使用 "GROUP BY" 語句。For example:

SELECT AVG(salary)
FROM employee;

傳回全部 salary 平均值

Another example:

SELECT AVG(salary)
FROM employee;
WHERE title = 'Programmer';

傳回 salary 平均值,條件為 employees 資料表中,當 title 等於 'Programmer'。

Example:

SELECT Count(*)
FROM employees;

傳回 employees 資料表中紀錄總筆數。

Use these tables for the exercises
items_ordered
customers

Review Exercises

1) 列出 price 欄位最大值(資料表: items_ordered)
2) 列出十月份所售出訂單 price 平均。

3) 取得 items_ordered 表中總筆數?

4) 列出來自 tent 訂單中price最少的值?

 

解答