sql和python統計ip(使用者)當天儲值總額

來源:互聯網
上載者:User

標籤:

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(使用者)當天儲值總額

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.