Home > database >  Table has two columns of data are respectively the ID and the DATE, how to query the DATE is not wit
Table has two columns of data are respectively the ID and the DATE, how to query the DATE is not wit

Time:10-11

Table has two columns of data are respectively the ID and the DATE, how to query the DATE is not within 30 days of
ID?
Table hope output
Id date id
1 5/1 4
2 5/2
3 5/3 when
1 4/1
2 4/2
3 four thirds
4 4/4
1 3/1
2 l
3 3/3
4 3/4

Now query the date can be implemented within 30 days, the output 1/2/3
Query the date in 30 days can be achieved, the output 1/2/3/4
No record within 30 days is not output, the output of 4

CodePudding user response:

Select distinct id from TB a
Where not the exists (select 1 from TB b where Anderson, d=b.i d and b.d ate> Date_add (now (), interval - 30 day))
  • Related