如果我们想在 SELECT 查询中对非分组字段使用分组函数,则必须使用 GROUP BY 子句。一般语法可以如下
mysql> Select COUNT(*), id from Student GROUP BY id; +----------+------+ | COUNT(*) | id | +----------+------+ | 1 | 1 | | 1 | 2 | | 1 | 15 | | 1 | 17 | | 1 | 20 | +----------+------+ 5 rows in set (0.00 sec) mysql> Select COUNT(*), address from Student GROUP BY id; +----------+---------+ | COUNT(*) | address | +----------+---------+ | 1 | Delhi | | 1 | Mumbai | | 1 | Delhi | | 1 | Shimla | | 1 | Jaipur | +----------+---------+ 5 rows in set (0.00 sec)
GROUP BY 子句后的字段可以与 SELECT 查询中给出的非组字段不同。
以上就是我们如何在 MySQL SELECT 查询中将组函数与非组字段一起使用?的详细内容,更多请关注php中文网其它相关文章!
已抢23080个
抢已抢117484个
抢已抢139072个
抢已抢6149个
抢已抢34802个
抢已抢7649个
抢