我把表连同数据贴出来,帮个忙啊!
DROP TABLE IF EXISTS `km_toolclick_cnt`;
CREATE TABLE `km_toolclick_cnt` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
`loginId` varchar(50) NOT NULL COMMENT '登录帐号',
`toolName` varchar(50) NOT NULL COMMENT '工具栏名称',
`goTime` datetime NOT NULL COMMENT '访问时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of km_toolclick_cnt
-- ----------------------------
INSERT INTO `km_toolclick_cnt` VALUES ('1', 'admin', '反馈信息 ', '2013-02-18 11:45:25');
INSERT INTO `km_toolclick_cnt` VALUES ('2', 'admin', 'bbbbbbbbbbbbb', '2013-03-15 14:36:05');
最后我想要的结果:
toolName cnt
--------------------------------------------
反馈信息 1
bbbbbbbbbbbbb 1
sql 分组求和 行转列
------解决方案--------------------
select toolname,count(1) from km_toolclick_cnt
group by toolname
------解决方案--------------------
select toolName,ct=count(1) from tb group by toolName