当前位置:Gxlcms > 数据库问题 > sql和python统计ip(用户)当天充值总额

sql和python统计ip(用户)当天充值总额

时间:2021-07-01 10:21:17 帮助过:1人阅读

sql查询当天的充值记录导入

sql code

--查询当天的数据
select * from a where generateTime=sysdate
--查询一个星期的数据
select * from a where (sysdate-generaeTime)=7
--查询一个月的数据
select * from a where months_between(sysdate,generateTime)=1 
--查询某一天的数据
select * from table where col between ‘2009-7-17‘ and ‘2009-7-18‘
select * from tb where datetime >‘2010-5-14‘ and datetime<‘2010-5-15‘
--一周内
SELECT * FROM TB WHERE datediff(dd,DATE_TIME,getdate()) <= 7
SELECT * FROM TB WHERE datediff(dd,DATE_TIME,getdate()) between 0 and 7
--从现在起往前算24小时内
SELECT * FROM TB WHERE dateiff(hh,DATE_TIME,getdate())<=24
SELECT * FROM TB WHERE datediff(hh,DATE_TIME,getdate()) between 0 and 23--
--如果是datetime的话
select 姓名,sum(价格) as 总金额 from 销售表 where convert(varchar(6),成交时间,112)=‘201311‘ group by 姓名    
 
--如果日期是字符型的话
select 姓名,sum(价格) as 总金额 from 销售表 where left(成交时间,7)=‘2013-11‘  group by 姓名

python统计脚本

cat log.txt
#时间   IP  充值额度
2015-8-2 13:23:23     192.168.1.1  33
2015-8-2 13:23:23     192.168.1.1  36
2015-8-2 13:23:24     192.168.1.1  43
2015-8-2 13:23:25     192.168.1.3  23
2015-8-2 13:23:25     192.168.1.1  43
2015-8-2 13:23:34     192.168.1.3  93
2015-8-2 13:23:50     192.168.1.1  33
2015-8-2 13:23:50     192.168.1.1  23
2015-8-2 13:23:59     192.168.1.4  43
2015-8-2 13:23:59     192.168.1.4  53
2015-8-2 13:24:30     192.168.10.1  25
2015-8-2 13:24:30     192.168.10.1  25
2015-8-2 13:24:30     192.168.10.1  25
2015-8-2 13:24:30     192.168.10.1  25
============================================
Logfile=‘log.txt‘
ipa={}
f=open(Logfile, ‘r‘).readlines()
for i in f:
    ip=i.split()
    if ipa.get(ip[2]) == None:
        ipa.setdefault(ip[2], ip[3])
    else:
        ipa[ip[0]]+=ip[3]
  
print(‘当日每IP的充值总额‘)
sorted(ipa.items())
for i in ipa:
    print(i,‘当天充值总额为:‘,ipa.get(i))

sql和python统计ip(用户)当天充值总额

标签:

人气教程排行