`id` bigint(20) NOT NULL AUTO_INCREMENT,
`content` text,
`event_id` bigint(20) unsigned DEFAULT NULL,
`content_md5` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5460 DEFAULT CHARSET=utf8;
insert into a(event_id,content_md5) values (1,'47bce5c74f589f4867dbd57e9ca9f808')
insert into a(event_id,content_md5) values (1,'47bce5c74f589f4867dbd57e9ca9f808')
insert into a(event_id,content_md5) values (2,'47bce5c74f589f4867dbd57e9ca9f808')
insert into a(event_id,content_md5) values (1,'47bce5c74f589f4867dbd57e9ca9f803')
insert into a(event_id,content_md5) values (2,'47bce5c74f589f4867dbd57e9ca9f808')
insert into a(event_id,content_md5) values (1,'47bce5c74f589f4867dbd57e9ca9f804')
insert into a(event_id,content_md5) values (3,'47bce5c74f589f4867dbd57e9ca9f808')
insert into a(event_id,content_md5) values (1,'47bce5c74f589f4867dbd57e9ca9f804')
需要得到结果:
event_id count content_md5
1 2 47bce5c74f589f4867dbd57e9ca9f808
1 1 47bce5c74f589f4867dbd57e9ca9f803
1 2 47bce5c74f589f4867dbd57e9ca9f804
2 2 47bce5c74f589f4867dbd57e9ca9f808
3 1 47bce5c74f589f4867dbd57e9ca9f808
就是一个表按照两个字段进行分组统计个数,sql怎么写呢,哪位大神告诉一下?
1 个解决方案
#1
select event_id,count(*) as [ count ], content_md5 from a group by event_id,content_md5
#1
select event_id,count(*) as [ count ], content_md5 from a group by event_id,content_md5