首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

统计数量并返回,该如何处理

2012-02-06 
统计数量并返回mysql,5.1,有如下sql语句,-- ------------------------------ Table structure for `ppmytj

统计数量并返回
mysql,5.1,有如下sql语句,
-- ----------------------------
-- Table structure for `ppmytj`
-- ----------------------------
DROP TABLE IF EXISTS `ppmytj`;
CREATE TABLE `ppmytj` (
  `id` int(11) NOT NULL auto_increment,
  `ques` varchar(255) NOT NULL,
  `typename` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=100 DEFAULT CHARSET=gbk;

-- ----------------------------
-- Records of ppmytj
-- ----------------------------
INSERT INTO `ppmytj` VALUES ('31', '点石家装', 'decorationcompany');
INSERT INTO `ppmytj` VALUES ('32', '宇杰装饰', 'decorationcompany');
INSERT INTO `ppmytj` VALUES ('33', '鼎佳装饰', 'decorationcompany');
INSERT INTO `ppmytj` VALUES ('34', '马可波罗瓷砖', 'stone');
INSERT INTO `ppmytj` VALUES ('35', '宏陶陶瓷', 'stone');
INSERT INTO `ppmytj` VALUES ('36', '菲林格尔', 'floors');
INSERT INTO `ppmytj` VALUES ('37', '马克森地板', 'floors');
INSERT INTO `ppmytj` VALUES ('38', '三星地板', 'floors');
INSERT INTO `ppmytj` VALUES ('39', '法瑞集成环保灶', 'kitchen');
INSERT INTO `ppmytj` VALUES ('40', '老板电器', 'kitchen');
INSERT INTO `ppmytj` VALUES ('41', '方太电器', 'kitchen');
INSERT INTO `ppmytj` VALUES ('42', '尚高卫浴', 'bathroom');
INSERT INTO `ppmytj` VALUES ('43', '九牧卫浴', 'bathroom');
INSERT INTO `ppmytj` VALUES ('44', '奥特朗电热水器', 'bathroom');
INSERT INTO `ppmytj` VALUES ('45', '宝兰吊顶', 'ceilings');
INSERT INTO `ppmytj` VALUES ('46', '楚楚吊顶', 'ceilings');
INSERT INTO `ppmytj` VALUES ('47', '扬子集成吊顶', 'ceilings');
INSERT INTO `ppmytj` VALUES ('48', '绿娃门窗', 'doorwindow');
INSERT INTO `ppmytj` VALUES ('49', '欧派木门', 'doorwindow');
INSERT INTO `ppmytj` VALUES ('50', '盼盼安居门', 'doorwindow');
INSERT INTO `ppmytj` VALUES ('51', '马克森衣柜', 'furniture');
INSERT INTO `ppmytj` VALUES ('52', '九鑫家俬', 'furniture');
INSERT INTO `ppmytj` VALUES ('53', '巨桑家私', 'furniture');
INSERT INTO `ppmytj` VALUES ('54', '欧特朗照明', 'buildingmaterials');
INSERT INTO `ppmytj` VALUES ('55', '朗斯地暖', 'buildingmaterials');
INSERT INTO `ppmytj` VALUES ('56', '欧雅壁纸', 'decoration');
INSERT INTO `ppmytj` VALUES ('57', '瑞丽布艺', 'decoration');
INSERT INTO `ppmytj` VALUES ('58', '青花瓷墙纸', 'decoration');
INSERT INTO `ppmytj` VALUES ('59', '宏图三胞', 'appliancestores');
INSERT INTO `ppmytj` VALUES ('60', '商之都.国生电器', 'appliancestores');
INSERT INTO `ppmytj` VALUES ('61', '壹品装饰', 'decorationcompany');
INSERT INTO `ppmytj` VALUES ('62', '喜来登装饰', 'decorationcompany');
INSERT INTO `ppmytj` VALUES ('63', '光明美家', 'decorationcompany');
INSERT INTO `ppmytj` VALUES ('64', '金舵陶瓷', 'stone');
INSERT INTO `ppmytj` VALUES ('65', '诺贝尔瓷砖', 'stone');
INSERT INTO `ppmytj` VALUES ('66', '百得防水', 'stone');
INSERT INTO `ppmytj` VALUES ('67', '冠珠陶瓷', 'stone');
INSERT INTO `ppmytj` VALUES ('68', '大自然地板', 'floors');
INSERT INTO `ppmytj` VALUES ('69', '兔宝宝板材', 'floors');
INSERT INTO `ppmytj` VALUES ('70', '世友地板', 'floors');
INSERT INTO `ppmytj` VALUES ('71', '法瑞集成环保灶', 'kitchen');
INSERT INTO `ppmytj` VALUES ('72', '志邦厨柜', 'kitchen');
INSERT INTO `ppmytj` VALUES ('73', '康佳厨卫电器', 'kitchen');
INSERT INTO `ppmytj` VALUES ('74', '桑夏太阳能', 'bathroom');
INSERT INTO `ppmytj` VALUES ('75', '华帝太阳能', 'bathroom');
INSERT INTO `ppmytj` VALUES ('76', '皇明太阳能', 'bathroom');
INSERT INTO `ppmytj` VALUES ('77', '德国欧卫集成吊顶', 'ceilings');
INSERT INTO `ppmytj` VALUES ('78', '扬子集成吊顶', 'ceilings');
INSERT INTO `ppmytj` VALUES ('79', '友邦集成吊顶', 'ceilings');
INSERT INTO `ppmytj` VALUES ('80', '合室家室内门', 'doorwindow');
INSERT INTO `ppmytj` VALUES ('81', '大洋豪门', 'doorwindow');
INSERT INTO `ppmytj` VALUES ('82', '扬金移门', 'doorwindow');
INSERT INTO `ppmytj` VALUES ('83', '美蒂娅移门整体衣柜', 'furniture');
INSERT INTO `ppmytj` VALUES ('84', '巨桑家私', 'furniture');
INSERT INTO `ppmytj` VALUES ('85', '喜临门法诗曼床垫', 'furniture');
INSERT INTO `ppmytj` VALUES ('86', '嘉美照明', 'buildingmaterials');
INSERT INTO `ppmytj` VALUES ('87', '欧特朗照明', 'buildingmaterials');


INSERT INTO `ppmytj` VALUES ('88', '瑞斯博地暖', 'buildingmaterials');
INSERT INTO `ppmytj` VALUES ('89', '爵迈墙纸', 'decoration');
INSERT INTO `ppmytj` VALUES ('90', '装饰家漆', 'decoration');
INSERT INTO `ppmytj` VALUES ('91', '多乐士漆', 'decoration');
INSERT INTO `ppmytj` VALUES ('92', '华海3C数码广场', 'appliancestores');
INSERT INTO `ppmytj` VALUES ('93', '商之都.国生电器', 'appliancestores');
INSERT INTO `ppmytj` VALUES ('94', '五星电器', 'appliancestores');

需要统计出这样的结果,在typename值相同的情况下,统计每个ques列的值出现的次数
例如
ques num typename
点石家装 3 decorationcompany
宇杰装饰 4 decorationcompany
鼎佳装饰 1 decorationcompany

这是一个投票结果的表

[解决办法]
SELECT ques,typename, COUNT(*) FROM ppmytj GROUP BY typename,ques;
部分结果:
appliancestores宏图三胞1
appliancestores华海3C数码广场1
appliancestores商之都.国生电器2
appliancestores五星电器1
bathroom奥特朗电热水器1
bathroom华帝太阳能1
bathroom皇明太阳能1
bathroom九牧卫浴1
bathroom桑夏太阳能1
bathroom尚高卫浴1
[解决办法]
楼主需要描述一下这个结果是如何得出来的。
点石家装 3 decorationcompany

这个3是怎么算出来的?
[解决办法]
select ques,count(ques,typename),typename from ppmytj where typename="xx" group by ques,typename;

热点排行