MySQL 기간 검색 쿼리

-- Date 형 예제
  SELECT 
    userid,
    sender,
    TIME 
  FROM
    cims_received_message 
  WHERE TIME >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) && TIME <= CURDATE() ;
 
-- Datetime 형 예제
SELECT 
  userid,
  sender,
  TIME 
FROM
  cims_received_message 
WHERE TIME >= DATE_SUB(NOW(), INTERVAL 1 MONTH) && TIME <= NOW() ;

Date Type 과 Datetime Type 둘다 상관 없이 됩니다.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s