mysql聚合查询

浏览:1187 发布日期:2017/06/26 分类:用法示例 关键字: 聚合查询
原生的mysql局和查询
mysql> SELECT * FROM test;+----+----------+
| id | username |
+----+----------+
| 1 | John |
| 2 | Mary |
| 3 | 1%Lily |
| 4 | Rose |
| 5 | NULL |
| 6 | Mary |
| 7 | Mary |
| 8 | H |
+----+----------+mysql> SELECT AVG(id) FROM test;  +---------+
| AVG(id) |
+---------+
| 4.5000 |
+---------+mysql> SELECT COUNT(id) AS counts FROM test;+--------+
| counts |
+--------+
| 8 |
+--------+mysql> SELECT MAX(id) AS counts FROM test;+--------+
| counts |
+--------+
| 8 |
+--------+mysql> SELECT MIN(id) AS counts FROM test;+--------+
| counts |
+--------+
| 1 |
+--------+mysql> SELECT SUM(id) AS counts FROM test;+--------+
| counts |
+--------+
| 36 |
+--------+
一般不会对数据表中的id进行操作,这里只是...
评论( 相关
后面还有条评论,点击查看>>