mysql中的with rollup
来源:互联网 发布:诸神黄昏升级数据 编辑:程序博客网 时间:2024/06/05 06:47
表如下:
CREATE TABLE `test3` (
`id` int(5) unsigned NOT NULL AUTO_INCREMENT,
`name1` varchar(10) DEFAULT NULL,
`name2` varchar(10) DEFAULT NULL,
`cnt` int(2) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1
insert into test3 (id,name1,name2,cnt)
values ('1','rank1', 'subrank1', '1'),
('2', 'rank1' ,'subrank1', '2'),
('3' ,'rank2' ,'subrank1', '1'),
('4', 'rank2' ,'subrank2', '2'),
('5', 'rank3' ,'subrank1', '1'),
('6', 'rank1', 'subrank2','3')
查询(1):
select name1,name2,sum(cnt) from test3 group by name1;
得到结果:
rank1subrank16
rank2subrank13
rank3subrank11
查询(2):
select name1,name2,sum(cnt) from test3 group by name1 with rollup;
rank1subrank16
rank2subrank13
rank3subrank11
nullsubrank1 10
查询(3):
select name1,name2,sum(cnt) from test3 group by name1,name2
得到结果:
rank1 subrank1 3
rank1 subrank2 3
rank2 subrank1 1
rank2 subrank2 2
rank3 subrank1 1
查询(4):
select name1,name2,sum(cnt) from test3 group by name1,name2 with rollup
得到结果:
rank1 subrank1 3
rank1 subrank2 3
rank1 NULL 6
rank2 subrank1 1
rank2 subrank2 2
rank2 NULL 3
rank3 subrank1 1
rank3 NULL 1
NULL NULL 10
可以看到多出了汇总信息
可以使用 rollup得到group by 按照分组条件分组时 不同分组条件的总数,( 在多条件group by 时 使用较多,单个分组条件时可以使用 count 得到总数目),缺点是 使用了rollup 无法再使用 order by
- MySQL中的WITH ROLLUP
- MySQL中的WITH ROLLUP
- MySQL中的WITH ROLLUP
- MySQL中的WITH ROLLUP
- mysql中的with rollup
- MySQL WITH ROLLUP
- MYSQL API之 WITH ROLLUP
- mysql group by with rollup
- MySQL中with rollup的用法
- mysql 之with rollup 的使用
- 使用mysql中的with rollup得到group by的汇总信息
- MYSQL group by 语句中的with rollup是用来干什么的?
- 使用mysql中的with rollup得到group by的汇总信息
- 使用mysql中的with rollup得到group by的汇总信息
- WITH ROLLUP在zend framework中的写法
- Mysql的with rollup功能(5.1以上版本)
- mysql group by 使用技巧及其with rollup使用
- Mysql 使用with rollup对聚合结果进行聚合
- 回调
- 如何使用APMServ本地搭建多个网站
- 2017-2-13-慕课网学习PHP
- Glide的进一步学习
- Android 安全框架 -- 总概
- mysql中的with rollup
- 总结--美丽的敷衍
- 'putText' is not a member of 'cv'
- 如何提高android代码的质量(CheckStyle、Findbugs、PMD、Lint)
- 公司沟通策略
- Android服务Services小结(二)
- html5多媒体组件API
- php 正则
- 破解linux root密码