易截截图软件、单文件、免安装、纯绿色、仅160KB

使用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
可以看到多出了汇总信息


相关文档:

Java+Mysql的数据库查找实现


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命令

1. 连接mysql:
mysql -h 主机地址 -u 用户名 -p
2.退出mysql:exit
3. 修改密码:
mysqlbinmysqladmin -uroot -p(oldpassword) password newpassword
4.增加用户:
添加一个用户test1 密码为ABC;让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入
mysql,然后键入以下命 ......

mysql中的union和order by、limit

我有一个表
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 ......

mysql中的正则表达式搜索

语法:
select * from table_name where column_name regexp '正则表达式'
或区分大小写
select * from table_name where column_name regexp binary '正则表达式'
支持的正则表达式符号:
.    任意字符
|    或,如:a|b|c
[]   范围,比如:[a-z],[0-9],[^0-9]不包 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号