2020-06-02
阅读量:
537
distinct和group by 用法有什么不同呀?
他们的基本功能是不同的
distinct消除重复行。
group by是分组语句。
group by 必须在查询结果中包含一个聚集函数,而distinct不用
比如有张表数据如下:
部门1 100
部门1 15
部门1 15
部门2 100
部门3 200
--每个部门有多少钱
select sum(金额),部门 from table
group by 部门
结果:
部门1 130
部门2 100
部门3 200
--把相同的记录不显示出来
select distinct 部门,金额 from table
结果:
部门1 100
部门1 15
部门2 100
部门3 200






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论