使用mysql中的with rollup得到group by的汇总信息
使用mysql中的with rollup可以得到每个分组的汇总级别的数据:
表如下:
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
数据为:
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,name2
得到结果:
rank1 subrank1 3
rank1 subrank2 3
rank2 subrank1 1
rank2 subrank2 2
rank3 subrank1 1
查询(2):
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
可以看到多出了汇总信息
相关文档:
数据库特点
--使用partition,存在上百个分区
--建表时指定了data_dir和index_dir,数据不是存储在默认位置,而是在mysqld的数据目录下link到真正的数据文件
备份恢复要求
--备份出来的数据恢复时要恢复成不同的表名
--恢复出来的数据实际存储位置也要存储在与原表不同的位置
问题
如果直接mysqldump-sourc ......
【书名】高性能MySQL(第二版)
【原书名】High Performance MySQL, second edition
【作者】Baron Schwartz,Peter Zaitsev,Vadim
Tkachenko,Jeremy D.Zawodny,Arjen Lentz,Derek
J.Balling 著
【译者】王小东 李军 康建勋 译
【出版社】电子工业出版社
【书号】978- ......
public class select {
public List XiuGai_select(String keyword){
List list=new ArrayList();
Connection conn = null;
Statement stmt = null;
String sql=null;
ResultSet res = null;
get ......
MySQL存储过程的参数用在存储过程的定义,共有三种参数类型,IN,OUT,INOUT,形式如:
CREATE PROCEDURE([[IN |OUT |INOUT ] 参数名 数据类形...])
1、IN 输入参数:表示该参数的值必须在调用存储过程时指定,在存储过程中修改该参数的值不能被返回,为默认值
2、OUT 输出参数:该值可在存储过程内部被改变,并可返回
3、I ......
我有一个表
CREATE TABLE `test1` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`desc` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
(1)以下查询会报错误:[Err] 1221 - Incorrect usage of UNION and ORDE ......