设为首页 加入收藏

TOP

SQL distinct和group by
2014-11-24 02:52:25 来源: 作者: 【 】 浏览:2
Tags:SQL distinct group
SQL distinct和group by
聚合函数
AVG
MAX
MIN
SUM
COUNT
distinct和Group by 区别:
distinct只是将重复的行从结果中出去;
group by是按指定的列分组,一般这时在select中会用到聚合函数。
distinct是把不同的记录显示出来。
group by是在查询时先把纪录按照类别分出来再查询。
group by 必须在查询结果中包含一个聚集函数,而distinct不用。
假定 Table 表有三列,
id, key, value
其中 id是主键,不能重复,key和value可能有重复记录
使用distinct去重复:
select distinct key,value
from table
不能显示主键。
使用group by 去重复
select count(*) from table A,
(select key,value, min(id) PID
from table group by key,value
) B
where A.id=b.PID
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇锋利的SQL:时间段天数统计 下一篇sql server时间函数语句

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Shell 基本运算符 - (2025-12-24 09:52:56)
·Shell 函数 | 菜鸟教 (2025-12-24 09:52:54)
·Linux 常用命令集合 (2025-12-24 09:52:51)
·socket 编程如何实现 (2025-12-24 09:20:41)
·Python创建简易的Soc (2025-12-24 09:20:39)