sql server - Select row where all records with similar row meet condition -
i have table many records, example..
id | user id | date 1 | 1 | 2014-05-26 2 | 1 | 2015-05-08 3 | 2 | 2014-05-20
i trying select user_id records date more 6 months passed, dont include them if there record same user_id not meet criteria. example, want return record user id 2.
my issue can
select user_id table datediff(month, date, getdate()) > 6
but still return record user_id 1. sure super easy have not been able make progress on this.
just take statement , take other away:
userswithyoungerdates ( select user_id table datediff(month, date, getdate()) <= 6 ) select user_id table datediff(month, date, getdate()) > 6 , user_id not in(select user_id userswithyoungerdates)
Comments
Post a Comment