请高手分析下这个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的汇聚
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
select gtp_bytes as gtp_bytes from TEMP group by src,dst
不是标准的SQL语句
不是标准的SQL语句
作者: wwwwb 发布时间: 2011-06-10
引用 1 楼 wwwwb 的回复:
select gtp_bytes as gtp_bytes from TEMP group by src,dst
不是标准的SQL语句
select gtp_bytes as gtp_bytes from TEMP group by src,dst
不是标准的SQL语句
那应该怎么写
作者: w_zhen_x 发布时间: 2011-06-10
union 改成union all试试. ^^
作者: kimsung 发布时间: 2011-06-10