Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. ID Code Date
  2.  
  3. 5525 X 2010-10-07
  4. 5525 Y 2010-11-25
  5. 5525 Y 2010-11-29
  6. 5525 Y 2010-10-06
  7. **5525 X 2011-01-14**
  8. **5525 X 2011-01-31**
  9. 5525 Y 2010-12-09
  10. 5525 Y 2010-10-15
  11. 5525 X 2010-10-18
  12. 5525 Y 2010-12-08
  13. 5525 X 2010-12-09
  14.  
  15. select ID from table
  16. where code in (X,Y)
  17. and date <= DATEADD(dd, -540, CURRENT_TIMESTAMP)
  18.  
  19. SELECT t1.ID FROM table_x t1
  20. WHERE
  21. t1.Date <= DATEADD(dd, -540, CURRENT_TIMESTAMP) AND
  22. -- you can add other criterias here as well, like t1.Code in (X,Y)
  23. t1.ID NOT IN (
  24. SELECT ID FROM table_x t2
  25. WHERE
  26. t2.Date > DATEADD(dd, -540, CURRENT_TIMESTAMP)
  27. -- you can add other criterias here as well, like t2.Code in (Z,F)
  28. );
  29.  
  30. SELECT *
  31. FROM table1
  32. WHERE id NOT IN (
  33. SELECT id
  34. FROM table1
  35. WHERE Date <= DATEADD(dd, -540, CURRENT_TIMESTAMP)
  36. )
  37. AND code in ('X','Y')
  38.  
  39. SELECT ID, Code, [Date]
  40. FROM tablename t
  41. WHERE NOT EXISTS (
  42. SELECT *
  43. FROM tablename
  44. WHERE ID = t.ID AND NOT (
  45. Code IN ('X','Y')
  46. AND [Date] <= DATEADD(dd, -540, CURRENT_TIMESTAMP))
  47. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement