分享
select count(1),count(distinct stbid) from diversion where  day='20171111' and starttime>='20171111181000' and starttime<'20171111185000' and (areacode='440100') and content='1214' and (type='10' or type='11') group by type order by type;

select count(1),count(distinct stbid) from diversion where  day='20171111' and starttime>='20171111181000' and starttime<'20171111185000' and (areacode='440100') and content='1214' and (type='10' or type='11');
微信图片_20171121123001.png
微信图片_20171121123017.png

已有(5)人评论

跳转到指定楼层
逆光之处是快乐 发表于 2017-11-21 12:34:33
这个结果为什么不一样??????
回复

使用道具 举报

逆光之处是快乐 发表于 2017-11-21 12:36:18
怎们样改就和下面那张图的结果一样了???
回复

使用道具 举报

逆光之处是快乐 发表于 2017-11-21 12:39:39
第一个sql语句怎们改就和第二张图的结果一样了
回复

使用道具 举报

SuperDove 发表于 2017-11-21 13:37:54
这个很明显,你把第一个sql的type子段显示出来看结果就知道了,第一个sql对type做了group,两条记录的type值是不一样的
回复

使用道具 举报

nextuser 发表于 2017-11-21 16:05:18
逆光之处是快乐 发表于 2017-11-21 12:39
第一个sql语句怎们改就和第二张图的结果一样了

把group by type去掉,应该两个就一致了。
因为一旦分组后,统计的类别就发生了变化。
比如有红苹果10和绿苹果10。
一旦group by ,就会对红苹果和绿苹果单独统计。
出现的结果就会如下:
苹果
红色 10
绿色 10

如果不做group by,就会出现如下结果:
苹果
20

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条