- 论坛徽章:
- 0
|
本帖最后由 李寻欢92 于 2010-04-18 09:18 编辑
既然是网站,为什么不用数据库
以mysql为例
1.建表
use test;/* 把表bbs存在数据库test里面 */
create table bbs (
pid int,
uid int,
ip varchar(15)
);
2.加载数据
load data local infile 'datafile' into table bbs;
如果datafile字段不是以制表符间隔,用以下命令
load data local infile 'datafile' into table bbs
fields terminated by ' '
lines terminated by '\n'
3.查询query.sql
use test;
select b.ip,b.num,a.uid,a.num from
(select ip,uid,count(*) num from bbs group by uid order by count(uid) desc limit 5) a,
(select ip,count(*) num from bbs group by ip ) b
where a.ip=b.ip order by b.ip,a.num desc;
4.输出结果mysql<query.sql>result
ip num uid num
202.207.177.1 3 1000 2
202.207.177.1 3 1006 1
202.207.177.2 2 1001 1
202.207.177.2 2 1002 1
各字段含义为,ip地址,同一ip总文章,用户id,此id发表文章数。
5.善后
sed '1d' result>result1 |
|