用户名: 密码: 忘记密码? 注册
收藏此问题 发表新评论

请高手分析下这个SQL语句,关于group by 和 sum的

create view TEMP as Select src as src, dst as dst, sum(gtp_bytes) as gtp_bytes From t1 where ( ( dst = -2067090979 )) group by src,dst 
union Select src as src, dst as dst, sum(gtp_bytes) as gtp_bytes From t1 where ( ( dst = -2067090979 )) group by src,dst  
union Select src as src, dst as dst, sum(gtp_bytes) as gtp_bytes From t1 where ( ( dst = -2067090979 )) group by src,dst  

执行这个SQL语句建立了一个视图
然后分别执行
select gtp_bytes as gtp_bytes from TEMP group by src,dst
select sum(gtp_bytes) as gtp_bytes from TEMP group by src,dst
这两个语句得到的查询结果不同,这是为什么
按我的理解在创建视图的时候已经做了sum的汇聚

昵称: w_zhen_x  时间: 2011-06-10 17:18:23
select gtp_bytes as gtp_bytes from TEMP group by src,dst
不是标准的SQL语句
昵称: wwwwb  时间: 2011-06-10 17:21:43
引用 1 楼 wwwwb 的回复:

select gtp_bytes as gtp_bytes from TEMP group by src,dst
不是标准的SQL语句


那应该怎么写
昵称: w_zhen_x  时间: 2011-06-10 17:41:47
union 改成union all试试. ^^
昵称: kimsung  时间: 2011-06-10 18:19:58
发表评论
昵称:
内容:
验证: