Luca Reghellin
Luca Reghellin

Reputation: 8113

How to exclude certain years from a year(column) result?

Given the following code:

SELECT YEAR(post_date) AS y, count(ID) as posts_count
FROM fdr_posts p
WHERE 
    p.post_status = 'publish' 
    OR p.post_status = 'future' 
    AND p.post_type = 'event'
GROUP BY y
ORDER BY post_date ASC

How can I exclude from column y certain years? So, every year except say, 2016 and 2017?

Upvotes: 0

Views: 39

Answers (1)

Jacques Amar
Jacques Amar

Reputation: 1833

WHERE 
p.post_status IN ( 'publish' , 'future' ) 
AND p.post_type = 'event'
AND YEAR(p.post_date) NOT IN (2016,2017)

Upvotes: 3

Related Questions