我有以下格式的数据。
iPAddress + timeVisited
=========================
varchar + timestamp
我想要获取的是
知道如何完成这项工作吗?
答案 0 :(得分:1)
获取今天的所有记录
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());
希望它有所帮助。
答案 1 :(得分:-1)
以下是我使用的
select count(*) from myTable where DATE(myTime) = DATE(NOW());
select count(*) from myTable where YEAR(myTime) = YEAR(NOW()) AND WEEKOFYEAR(myTime) = WEEKOFYEAR(NOW());
select count(*) from myTable where YEAR(myTime) = YEAR(NOW()) AND MONTH(myTime) = MONTH(NOW());
select count(*) from myTable where YEAR(myTime) = YEAR(NOW());
YEAR(myTime) = YEAR(NOW())
起着非常重要的作用。
将日期视为2012-10-30
和2013-10-30
。