我的数据库中有一个简单的日志表。对于每个页面访问,插入一行。现在我想总结一下今天和昨天的某个专栏。
我尝试了以下查询:
SELECT Sum(CASE
WHEN `time` > 1364767200 THEN `sqlquerycount`
end) AS `today`,
Sum(CASE
WHEN `time` BETWEEN 1364684400 AND 1364767200 THEN `sqlquerycount`
end) AS `yesterday`
FROM `log`
以下 PHP 脚本的结果:
$sql = "SELECT
SUM(CASE WHEN `time` > ".strtotime("today")." THEN `sqlQueryCount` END) AS `today`,
SUM(CASE WHEN `time` BETWEEN ".strtotime("yesterday")." AND ".strtotime("today")." THEN `sqlQueryCount` END) AS `yesterday`
FROM `log`";
“昨天”仍为 NULL,但我认为此查询没有任何问题。任何的想法?