统计数据sql
mysql5.0 sql如下
DROP TABLE IF EXISTS `duanwu`;
CREATE TABLE `duanwu` (
`id` int(11) NOT NULL auto_increment,
`graspqydw` int(11) NOT NULL,
`familydw` int(11) NOT NULL,
`koreadw` int(11) NOT NULL,
`ipaddress` varchar(255) character set gb2312 NOT NULL,
`post_at` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
INSERT INTO `duanwu` VALUES ('1', '1', '1', '1', '127.0.0.1', '2012-06-18 10:24:04');
INSERT INTO `duanwu` VALUES ('2', '2', '2', '2', '127.0.0.1', '2012-06-18 10:45:28');
INSERT INTO `duanwu` VALUES ('3', '3', '3', '3', '127.0.0.1', '2012-06-18 10:45:36');
需要统计出如下结果,graspqydw为1的数量,graspqydw为2的数量graspqydw为3的数量
graspqydw num
1 1
2 1
3 1
------解决方案--------------------
select graspqydw,count(*)
from duanwu
group by graspqydw