我在我的數據庫中有一個簡單的日誌表。對於每個頁面訪問,插入一行。現在我想爲今天和昨天總結一個專欄。CASE BETWEEN聲明
我嘗試以下查詢:
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`";
「昨天」的剩餘空,但我沒有看到與此查詢任何問題。任何想法?
你使用'mariadb'或'mysql'嗎? – Kermit
我正在使用MariaDB。 – Zwirbelbart
'SELECT COUNT(*)FROM log WHERE time BETWEEN 1364684400 AND 1364767200'的結果是什麼? – Kermit