標籤:
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()) <= 7SELECT * FROM TB WHERE datediff(dd,DATE_TIME,getdate()) between 0 and 7--從現在起往前算24小時內SELECT * FROM TB WHERE dateiff(hh,DATE_TIME,getdate())<=24SELECT * 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 332015-8-2 13:23:23 192.168.1.1 362015-8-2 13:23:24 192.168.1.1 432015-8-2 13:23:25 192.168.1.3 232015-8-2 13:23:25 192.168.1.1 432015-8-2 13:23:34 192.168.1.3 932015-8-2 13:23:50 192.168.1.1 332015-8-2 13:23:50 192.168.1.1 232015-8-2 13:23:59 192.168.1.4 432015-8-2 13:23:59 192.168.1.4 532015-8-2 13:24:30 192.168.10.1 252015-8-2 13:24:30 192.168.10.1 252015-8-2 13:24:30 192.168.10.1 252015-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(使用者)當天儲值總額