Mysql Group by 使用解析

使用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 两个都相同的时候,才算是重复数据,仅有一个数据相同不是重复数据。

猜你喜欢

转载自www.cnblogs.com/liruijia/p/Mysql-Group-by-shi-yong-jie-xi.html
今日推荐