MySQL Forums
Forum List  »  Newbie

Re: keep last register and delete old ones from group.
Posted by: leandro roggerone
Date: March 14, 2018 12:36PM

Dear Peter ;
I think I got it ... I toke your join idea and a sub select query.
My query is as follows:

select t1,radacctid,t1.imsi,t1.acctstarttime from (SELECT radacctid,imsi,acctstarttime from lte_acct where imsi IN (select imsi from lte_acct where acctstoptime is NULL group by imsi HAVING COUNT(*) > 1 ) and acctstoptime is NULL order by imsi) t1 inner join (select imsi, max(acctstarttime) maxdt from lte_acct where acctstoptime is NULL group by imsi) t2 on t1.imsi=t2.imsi and t1.acctstarttime < t2.maxdt order by t1.imsi;

I think it is working so far.
Note: I added the statement "order by t1.imsi" but there is no effect on the output.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.