ID string
IDATE date
ID IDATE
AA 2017/05/01
AA 2017/05/02
AA 2017/05/03
AA 2017/05/03
BB 2017/05/01
BB 2017/05/02
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Want to according to the different ID, delete data is not the latest date, looking forward to the results
ID IDATE
AA 2017/05/03
AA 2017/05/03
BB 2017/05/02
How to write SQL for help you?
CodePudding user response:
Today just use a similar function, ACCESS2007 debugging through, but I don't know whether there is any better method,SELECT the table 2. ID, table 2. IDATE
FROM table 2,
(SELECT table 2. ID AS IID, Max ([IDATE]) AS NDATE
FROM table 2
GROUP BY ID) T
WHERE the table 2. The ID=T.I ID AND table 2. IDATE=T.N DATE
CodePudding user response:
The DELETE FROM the TAB
WHERE NOT the EXISTS (SELECT id, MAX (idate) FROM the TAB GROUP BY id)
CodePudding user response:
http://blog.csdn.net/xingxinglaile/article/details/30243243 hope this helps