- 论坛徽章:
- 0
|
1,创建表:
mysql> show create table accessLog\G
*************************** 1. row ***************************
Table: accessLog
Create Table: CREATE TABLE `accessLog` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`time` date NOT NULL,
`ip` int(10) unsigned NOT NULL,
`port` int(10) unsigned NOT NULL,
`flow` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=gbk
1 row in set (0.00 sec)
2,插入测试数据:
mysql> insert into accessLog values(null,current_date(), INET_ATON('192.168.0.1'),20,1000);
mysql> insert into accessLog values(null,current_date(), INET_ATON('192.168.0.1'),21,2000);
mysql> insert into accessLog values(null,current_date(), INET_ATON('192.168.0.1'),22,3000);
mysql> insert into accessLog values(null,current_date(), INET_ATON('192.168.0.2'),23,3000);
mysql> insert into accessLog values(null,current_date(), INET_ATON('192.168.0.2'),24,3000);
mysql> insert into accessLog values(null,current_date(), INET_ATON('192.168.0.2'),25,3000);
3,你所想要的sql和测试结果。 可以根据需要,再加一个索引。
mysql> select time as date,inet_ntoa(ip) as ip, sum(flow) as flow from accessLog group by date,ip;
+------------+-------------+------+
| date | ip | flow |
+------------+-------------+------+
| 2012-03-21 | 192.168.0.1 | 6000 |
| 2012-03-21 | 192.168.0.2 | 9000 |
+------------+-------------+------+
2 rows in set, 1 warning (0.00 sec)
|
评分
-
查看全部评分
|