I have a table like this:
ID_____PostingDate_____PosterID
--------------------------------
1______05/01/2012______450
2______06/30/2012______451
3______02/17/2013______451
4______12/10/2012______451
5______06/14/2012______452
6______06/15/2012______452
7______05/01/2012______453
8______06/04/2012______453
9______04/05/2013______454
10_____05/05/2013______454
I'm trying to get a list of all PosterIDs that have posted in May or June of 2012 and have not posted again since then.
Desired Result from the table above:
PosterID
--------
450
452
453
I've tried:
WHERE DATE_FORMAT(PostingDate, '%m-%Y') IN ('05-2012', '06-2012')
and
SELECT UNIQUE(a.PosterID)
FROM
(SELECT ID, PostingDate, PosterID FROM table WHERE DATE_FORMAT(PostingDate, '%m-%Y') IN ('05-2012', '06-2012')
) a
WHERE DATEDIFF(PostingDate, NOW()) > 365
though neither of these are getting close
Try this:
SELECT DISTINCT PosterID
FROM table1
WHERE PostingDate BETWEEN '2012-05-01' AND '2012-06-30'
AND posterID NOT IN (SELECT PosterID
FROM table1
WHERE PostingDate > '2012-07-01');
SELECT PosterID
FROM ( SELECT PosterID, MAX(PostingDate) AS latest_post
FROM tbl
GROUP BY 1) latest_posts
WHERE latest_post BETWEEN '2012-05-01' AND '2012-06-30'
ORDER BY PosterID;
尝试这样的事情:
where PostingDate < '2012-7-1' and PostingDate >= '2012-5-1'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.