2012-09-28 83 views
-1

我有一個表,如下所示:試圖按日期時間類型,但沒有時間與MySQL

block int not null 
    day datetime not null 
    user int 

我想

select day, count(*) 
    from TABLE 
    where date between date() and TARDATE 
    group by day 
    order by day desc 

的事情是,我想組由只有日期,而不是時間。

我會怎麼做在MySQL/PHP?

回答

3

嘗試

SELECT DATE(`day`) as `DAY`, COUNT(*) totalCount 
FROM TABLE 
WHERE date BETWEEN date() AND TARDATE 
GROUP BY DATE(`day`) 
ORDER BY day DESC 
+0

這會不會是也與年份和月份做什麼呢? – Fallenreaper

+0

@Fallenreaper是的。 –

+0

非常感謝John – Fallenreaper

0

試試這個

SELECT DATE(day), COUNT(*) as total_no FROM TABLE WHERE date (BETWEEN date() AND TARDATE) GROUP BY DATE(day) ORDER BY day DESC