当前位置:Gxlcms > 数据库问题 > Mysql Group by 使用解析

Mysql Group by 使用解析

时间:2021-07-01 10:21:17 帮助过:13人阅读

使用gruop by 分组

1. 方式一:select name from table1 group by name; 注意:group by 两侧都应该含有name,例如select country,name from table1 group by country,name;左右两侧是相同的数据。
2. 方式二:select name,count(age) from table1 group by name;注:当使用聚合函数的时候,不用放到group by 后面

distinct 使用

1. distinct可以用于筛选不重复的数据
2. 只能放置在select后面第一个单词的位置,例如:select distinct name from table1;
3. 如果是多个参数,那么只有在多个参数不同的情况下,才算数据不同,例如select distinct name,age from table1; 此时name age 两个都相同的时候,才算是重复数据,仅有一个数据相同不是重复数据。

Mysql Group by 使用解析

标签:注意   个数   第一个   相同   聚合函数   解析   数据   参数   不重复   

人气教程排行