Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ID Code Date
- 5525 X 2010-10-07
- 5525 Y 2010-11-25
- 5525 Y 2010-11-29
- 5525 Y 2010-10-06
- **5525 X 2011-01-14**
- **5525 X 2011-01-31**
- 5525 Y 2010-12-09
- 5525 Y 2010-10-15
- 5525 X 2010-10-18
- 5525 Y 2010-12-08
- 5525 X 2010-12-09
- select ID from table
- where code in (X,Y)
- and date <= DATEADD(dd, -540, CURRENT_TIMESTAMP)
- SELECT t1.ID FROM table_x t1
- WHERE
- t1.Date <= DATEADD(dd, -540, CURRENT_TIMESTAMP) AND
- -- you can add other criterias here as well, like t1.Code in (X,Y)
- t1.ID NOT IN (
- SELECT ID FROM table_x t2
- WHERE
- t2.Date > DATEADD(dd, -540, CURRENT_TIMESTAMP)
- -- you can add other criterias here as well, like t2.Code in (Z,F)
- );
- SELECT *
- FROM table1
- WHERE id NOT IN (
- SELECT id
- FROM table1
- WHERE Date <= DATEADD(dd, -540, CURRENT_TIMESTAMP)
- )
- AND code in ('X','Y')
- SELECT ID, Code, [Date]
- FROM tablename t
- WHERE NOT EXISTS (
- SELECT *
- FROM tablename
- WHERE ID = t.ID AND NOT (
- Code IN ('X','Y')
- AND [Date] <= DATEADD(dd, -540, CURRENT_TIMESTAMP))
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement