rollup 的汇总行和下面的总和不相等 是什么原因呢???
select decode(grouping(l.nareated), 1, '日期合计', to_char(l.nareated)) nareated,
count(distinct(case
when l.isindex = 0 then
l.userid
else
null
end)) viewpeople, -- 这个字段 汇总行和下面数据行总和不相等
count(distinct(case
when l.ischarge = 1 and l.msid is not null then
l.msid || l.productid
else
null
end)) bookpeople, -- 这个字段 汇总行和下面数据行总和不相等
sum(case
when l.isnewuser = 0 then
1
else
0
end) newusers,
sum(case
when l.isindex = 0 then
1
else
0
end) assces,
count(case
when l.ischarge = 1 and l.msid is not null then
l.userid
else
null
end) downs,
sum(case
when l.ischarge = 1 then
l.price
else
0
end) / 10 moneys
from t_wp_accesslog l, t_declare_dproduct p
where l.productid = p.productid
and l.msid is not null
and l.nareated between to_number('20080217') and to_number('20080218')
group by rollup(l.nareated)
order by nareated desc
-----------------------------------------------------------------------------------
结果如下:
NAREATED VIEWPEOPLE BOOKPEOPLE NEWUSERS ASSCES DOWNS MONEYS
日期合计 9288 3563 10732 24057 9695 19082
20080217 4659 1794 5202 11589 4514 8871.5
20080216 4989 1880 5530 12468 5181 10210.5
count(distinct(case
when l.isindex = 0 then
l.userid
else
null
end)) viewpeople, -- 这个字段 汇总行和下面数据行总和不相等
count(distinct(case
when l.ischarge = 1 and l.msid is not null then
l.msid || l.productid
else
null
end)) bookpeople, -- 这个字段 汇总行和下面数据行总和不相等
sum(case
when l.isnewuser = 0 then
1
else
0
end) newusers,
sum(case
when l.isindex = 0 then
1
else
0
end) assces,
count(case
when l.ischarge = 1 and l.msid is not null then
l.userid
else
null
end) downs,
sum(case
when l.ischarge = 1 then
l.price
else
0
end) / 10 moneys
from t_wp_accesslog l, t_declare_dproduct p
where l.productid = p.productid
and l.msid is not null
and l.nareated between to_number('20080217') and to_number('20080218')
group by rollup(l.nareated)
order by nareated desc
-----------------------------------------------------------------------------------
结果如下:
NAREATED VIEWPEOPLE BOOKPEOPLE NEWUSERS ASSCES DOWNS MONEYS
日期合计 9288 3563 10732 24057 9695 19082
20080217 4659 1794 5202 11589 4514 8871.5
20080216 4989 1880 5530 12468 5181 10210.5
...全文
相关推荐
sql rollup用法 小计汇总
这里介绍sql server2005里面的一个使用实例: CREATE TABLE tb(province nvarchar(10),city nvarchar(10),score int)INSERT tb SELECT ‘陕西’,’西安’,3UNION ALL SELECT ‘陕西’,’安康’,4UNION ALL SELECT ‘陕西’,’汉中’,2UNION ALL SELECT ‘广东’,’广州’,5UNION ALL SELECT ‘广东’,’珠海’,2UNION ALL SELECT ‘广东’,’东莞’,3UNION ALL SELECT ‘江苏’,’南京’,6UNION ALL
SQLServer中汇总功能的使用GROUPING,ROLLUP和CUBE
查看SQL Server的帮助才发现,厉害啊,原来还有这么厉害的东西,不由的想起以前做水晶报表的时候,原来在SQL Server中就可以实现这样的功能.
SQLServer 数据库的数据汇总完全解析(WITH ROLLUP)
乍一看,好像很容易,用group by好像能实现?但仔细研究下去,你又会觉得group by也是无能为力,总欠缺点什么,无从下手。那么,到底该如何做呢?别急,SQL Server早就帮我们做好了,下面,跟我来。
rollup,cube,grouping sets()的个人理解
rollup,cube,grouping sets()的个人理解 其中关于这三个的各种情况,举例论证这三个的区别。
SQL语句中Group BY 和Rollup以及cube用法
SQL语句中Group BY 和Rollup以及cube用法


