前言:python统计apache.nginx访问日志IP访问次数并且排序(显示前20条).其实用awk+sort等命令可以实现,用awk数组也可以实现,这里只是用python尝试下. apache脚本: ips = {} with open("/root/mail_access_log-20180629") as fh: for line in fh: ip = line.split(" ")[0] if 6 < len(ip) <=15: ips
sql中group by后,获取每组中的前N行数据,目前我知道的有2种方法 比如有个成绩表: 里面有字段学生ID,科目,成绩.我现在想取每个科目的头三名. 1. 子查询 select * from score s where StudentName in (select top 3 StudentName from score where s.Subjects = Subjects group by Subjects,StudentName,Score order by Score desc