2011-11-19 118 views

回答

4
SELECT * 
FROM yourTable 
WHERE (MONTH(yourDate) = 10 AND DAYOFMONTH(yourDate) >= 30) 
    OR (MONTH(yourDate) = 11) 
    OR (MONTH(yourDate) = 12 AND DAYOFMONTH(yourDate) <= 11) 
1
select * 
from table 
where 
concat(year(now()),right(date_field,6)) 
between 
concat(year(now()),'-10-30') 
and 
concat(year(now()),'-12-11') 
1

你可以試試這個?:

CREATE DEFINER=`root`@`localhost` PROCEDURE `GetByMonthAndDayRange` 
(
    IN monthFrom INT 
    , IN dayFrom INT 
    , IN monthTo INT 
    , IN dayTo INT 
) 
BEGIN 

    -- For good coding practice, name your columns instead of using * 
    SELECT * 
    FROM tablename 
    WHERE 
    (MONTH(datecolumnname) = monthFrom AND DAYOFMONTH(datecolumnname) >= dayFrom) 
    OR (MONTH(datecolumnname) > monthFrom AND  MONTH(datecolumnname) < monthTo) 
    OR (MONTH(datecolumnname) = monthTo AND DAYOFMONTH(datecolumnname) <= dayTo); 

END 

如果使用存儲過程(如果代碼工作,以自己的口味),你就可以更快地編寫代碼,只需提供參數(這是動態的)

+0

好主意,但與我在查詢中需要的其他東西它沒有工作。 – Scott

相關問題