2014-02-07 66 views
1

我發現了兩個類似的答案如何在MySQL中每個月7:15-12:15查詢一次?

SELECT Count(*) 
FROM fd_member 
WHERE From_unixtime(Unix_timestamp(add_time), '%h') >= 8 
     AND From_unixtime(Unix_timestamp(add_time), '%h') < 12 
GROUP BY CONVERT(add_time, CHAR(10)) 

SELECT * 
FROM fd_member f 
WHERE Date(f.date) >= Date('2013-10-01') 
     AND Date(f.date) < Date('2013-11-01') 
     AND Hour(f.date) >= Hour('8:00:00') 
     AND Hour(f.date) < Hour('12:00:00') 

但是他們並不是精確到分鐘。

+0

@Tiny thankyou非常多 – Vainlyh

回答

1
SELECT * 
FROM fd_member f 
WHERE Date(f.date) >= Date('2013-10-01') 
     AND Date(f.date) < Date('2013-11-01') 
     AND Time(f.date) >= Time('7:15:00') 
     AND Time(f.date) < Time('12:15:00') 

應該工作。搏一搏。如果不是你能提​​供一些SQL小提琴的樣本數據和你期望的

+0

非常感謝你親愛的。你的回答讓我突然清醒! – Vainlyh