Grouping and Aggregate Functions

Grouping Concepts

  • HAVING
    • because the GROUP BY must be after the WHERE

Aggregate Functions

function description
max() 返回最大值
min() 返回最小值
avg() 返回均值
sum() 返回总和
count() 计数

Implicit V.S. Explicit Groups

  • Implicit group: 不分组,直接使用max(),min()等aggregate function.(相当将所有的数据分到同一组)
  • Explicit group: 使用GROUP BY进行分组

Counting Distinct Values

  • SELECT COUNT(DISTINCT $fld_name) FROM $tb_name;

Using Expressions

  • SELECT MAX(datediff($fld_name1,$fld_name2))

Null

  • ignore null
    • count($fld_name) sum($fld_name) avg($fld_name)
  • not ignore null
    • count(*) 计算row的数目

results matching ""

    No results matching ""