SQL and Python statistics IP (user) top-up amount of the day

Source: Internet
Author: User

SQL query the day of the Recharge record import

SQL code

--Query the day's data select * from a where generatetime=sysdate--query for one weeks of data select * from  a where  (sysdate-generaetime) =7--query for one months data select * from a where months _between (sysdate,generatetime) =1 --query data for a given day 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 in a week  datediff (Dd,date_time,getdate ())  <= 7SELECT * FROM TB WHERE  DateDiff (Dd,date_time,getdate ())  between 0 and 7--24 hours forward from now Select * from  tb where dateiff (Hh,date_time,getdate ()) <=24select * from tb where  datediff (Hh,date_time,getdate ())  between 0 and 23----If it is datetime select  name, sum (price)  as  Total Amount  from  Sales table  where convert (varchar (6), closing time, 201311) = ' The name of '  group by  '       --If the date is character select  name, sum (price)  as  Total amount  from  sales form  where left (Deal time, 7) = ' 2013-11 '   group by  name

Python Statistics script

cat log.txt# time    IP   Recharge limit 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],&NBSP;IP[3])     else:        ipa[ip[0]]+=ip[ 3]  print (' total value per IP ') sorted (Ipa.items ()) For i in ipa:    print ( I, ' the total amount of the same day is: ', Ipa.get (i))

SQL and Python statistics IP (user) top-up amount for the day

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.