The code is as follows:
Selectt1.* from(SELECT ut. Transactionaccount,u.nickname,p.professorname'bound teacher', UB. UpdateTime as'Change Time'From dbo. Userbind UB JOIN dbo. UserTransaction UT on UB. UserId=UT. Useridjoin dbo. Users u on UB. UserId=u.useridjoin dbo. Professor P on P.id=UB. Professoridwhere u.isenable=1and UB. UpdateTime<'2016-01-18') T1inner join (SELECT UT. Transactionaccount,u.nickname,max (UB. UpdateTime) as'Change Time'From dbo. Userbind UB JOIN dbo. UserTransaction UT on UB. UserId=UT. Useridjoin dbo. Users u on UB. UserId=u.useridjoin dbo. Professor P on P.id=UB. Professoridwhere u.isenable=1and UB. updatetime<'2016-01-18'GROUP by UT. Transactionaccount,u.nickname) ast2on t1. Transactionaccount=T2. Transactionaccountand t1. Time of Change=t2. Time of Change
Writing ideas:
Take the maximum time column when you have a time column
With a self-increment ID, go to the maximum ID.
You can do this if you want to return a recordset and have a time column.
Select repeating columns, time columns, remaining columns
Inner JOIN (select repeating column, max (Time column) as Time column from table group by repeating column) as T2
on T1. Repeating column =t2. Repeating column and T1. Time column =t2. Time column
From table as T1
Summarize:
The code snippet is repeated a lot, what good method do we have???
Go to account number, nickname Repeat, and take the latest binding record