求MYSQL统计的语句
大家好,有一些MYSQL的数据统计麻烦一下大家。有如下表格
id gtype mtype money
1 1 1 20
2 1 1 30
3 1 2 20
4 2 0 43
5 2 0 45
6 1 0 35
7 2 4 40
8 1 5 70
9 1 2 30
10 1 0 43
11 2 1 37
12 2 2 34
MYSQL 创建 表 的语句如下:
create table `testsum` (
`id` double ,
`gtype` double ,
`mtype` double ,
`money` float
);
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('1','1','1','20');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('2','1','1','30');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('3','1','2','20');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('4','2','0','43');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('5','2','0','45');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('6','1','0','35');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('7','2','4','40');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('8','1','5','70');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('9','1','2','30');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('10','1','0','43');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('11','2','1','37');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('12','2','2','34');
需求:
按gtype进行分组,把mtype=0和mtype<>0的money分别求各统计出来,
分成两列,也就是结果如下
gtype mtype0money mtype2money
1 78 170
2 88 110
请大家帮帮忙。如果能用一句SQL语句就可以搞定那就最好,
如果不成,用存储过程也是可以的。
或者给我思路,让我自己去实现也行。麻烦大家了。
id gtype mtype money
1 1 1 20
2 1 1 30
3 1 2 20
4 2 0 43
5 2 0 45
6 1 0 35
7 2 4 40
8 1 5 70
9 1 2 30
10 1 0 43
11 2 1 37
12 2 2 34
MYSQL 创建 表 的语句如下:
create table `testsum` (
`id` double ,
`gtype` double ,
`mtype` double ,
`money` float
);
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('1','1','1','20');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('2','1','1','30');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('3','1','2','20');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('4','2','0','43');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('5','2','0','45');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('6','1','0','35');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('7','2','4','40');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('8','1','5','70');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('9','1','2','30');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('10','1','0','43');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('11','2','1','37');
insert into `testsum` (`id`, `gtype`, `mtype`, `money`) values('12','2','2','34');
需求:
按gtype进行分组,把mtype=0和mtype<>0的money分别求各统计出来,
分成两列,也就是结果如下
gtype mtype0money mtype2money
1 78 170
2 88 110
请大家帮帮忙。如果能用一句SQL语句就可以搞定那就最好,
如果不成,用存储过程也是可以的。
或者给我思路,让我自己去实现也行。麻烦大家了。
...全文
相关推荐
Mysql Sql语句注释大全
主要介绍了Mysql Sql语句注释大全,需要的朋友可以参考下
mysql每半小时平均值计算的sql语句
表结构: CREATE TABLE `instance` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `timestamp` int(10) unsigned DEFAULT NULL, `cpu` decimal(8,3) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB; 统计每半小时平均值,实现可以如下: select `timestamp`-`timestamp`% (5*60) , avg(cup) from `instance` group by `timestamp`
MySQL数据库语法
MySQL数据库基础语法知识,包括如何创建数据库表,添删改查等操作。
MySQL数据库考试题和答案解析.doc
MySQL数据库考试题和答案解析.doc
mysql代码-272统计测试使用
mysql代码-272统计测试使用


疑难问题
