Mysql 每天、每周、每月、每年打印数据
我有以下格式的数据Mysql 每天、每周、每月、每年打印数据,mysql,timestamp,Mysql,Timestamp,我有以下格式的数据 iPAddress + timeVisited ========================= varchar + timestamp 我想拿的是 每天具有总IP的报告(系统日期) 每周有总IP的报告(如果今天是星期二,我需要本周而不是最后7天) 每月总IP的报告(当月…如果今天是18,则从本月的1-18) 每年拥有总IP的报告 你知道怎么做吗?下面是我用的 当前日期 本周 当月 本年度 注: YEAR(myTime)=YEAR(NOW())在本周和本月起
iPAddress + timeVisited
=========================
varchar + timestamp
我想拿的是
YEAR(myTime)=YEAR(NOW())
在本周和本月起着非常重要的作用
将日期想象为
2012-10-30
和2013-10-30
以获取今天的所有记录
select iPAddress from table_name where date(timeVisited) = curdate();
获取当前周的所有记录
select iPAddress from table_name where week(timeVisited) = week(curdate()) and year(timeVisited) = year(curdate());
获取当月的所有记录
select iPAddress from table_name where month(timeVisited) = month(curdate()) and year(timeVisited) = year(curdate());
并获取本年度的所有记录
select iPAddress from table_name where year(timeVisited) = year(curdate());
希望能有帮助 “获取数据”不是那么清楚。。。你需要什么?不同ip地址的计数为1。2.3.4?`还有别的吗?@RaphaëlAlthaus:我需要每天、每周、每月、每年的总访问量……好吧,你能得到你想要的吗?很抱歉,这会给出不正确的数据(每周和每月)。。。2012年10月21日和2011年10月21日的周数相同,但年份错误。。。那么,当前年度周数是错误的……是什么阻止您稍微修改源并添加年度检查?比如“从表名称中选择iPAddress,其中周(timeVisited)=周(curdate())和年(timeVisited)=年(curdate());”我给了你线索。不难理解你需要从那里做什么。这个月也是如此!
select iPAddress from table_name where date(timeVisited) = curdate();
select iPAddress from table_name where week(timeVisited) = week(curdate()) and year(timeVisited) = year(curdate());
select iPAddress from table_name where month(timeVisited) = month(curdate()) and year(timeVisited) = year(curdate());
select iPAddress from table_name where year(timeVisited) = year(curdate());