SQL Aggregate函数
1.AVG() -返回平均值
2.COUNT() -返回行数
3.FIRST() -返回第一个记录的值
4.LAST() - 返回最后一个记录的值
5.MAX() - 返回最大值
6.MIN() - 返回最小值
7.SUM() - 返回总和
表名 access_log
1.下面的sql语句从表的“count”列中获取平均值
eg: SELECT AVG(count) AS CountAverage FROM access_log;
2.下面的sql语句选择访问量高于平均访问量的“site_id”和“count”
eg:SELECT site_id,count FROM access_log WHERE count>(SELECT AVG(count) FROM access_log);
1.查询所有记录的条数
select count(*) from access_log;
2.查询websites表中alexa列中不为空的记录的条数
select count(alexa) from websites;
3.查询websites表中alexa列中不重复的记录的条数
select count(distinct alexa) from websites;
1.从access_log表中的count列中获取最大值
select max(count) AS max_count from access_log;
2.从access_log表中的count列中获取最小值
select min(count) AS min_count from access_log;
3.下面的 SQL 语句查找 "access_log" 表的 "count" 字段的总数:
select sum(count) AS sum_count from access_log;