使用 gruop by 分组
方式一: select name from table1 group by name; 注意: group by 两侧都应该含有 name, 例如 select country,name from table1 group by country,name; 左右两侧是相同的数据.
方式二: select name,count(age) from table1 group by name; 注: 当使用聚合函数的时候, 不用放到 group by 后面
distinct 使用
distinct 可以用于筛选不重复的数据
只能放置在 select 后面第一个单词的位置, 例如: select distinct name from table1;
如果是多个参数, 那么只有在多个参数不同的情况下, 才算数据不同, 例如 select distinct name,age from table1; 此时 name age 两个都相同的时候, 才算是重复数据, 仅有一个数据相同不是重复数据.
来源: http://www.bubuko.com/infodetail-2996626.html