select termid,balanceNo from tab where termid in (select max(termid) from tab group by termid)
------解决方案--------------------
------解决方案-------------------- LS 貌似都没注意 他这张表是没有主键的。 楼主的方法 貌似是可以的。 为什么在sqlserver下运行不了,可以换种方法
select termid,balanceNo from tab where exists ( select * from (select termid,max(batchNo) as batchNo from tab where termid in('000001','000002','000003') group by termid ) a where a.termid=tab.termid and a.batchNo =tab.batchNo )
------解决方案-------------------- select termid,batchNo,balanceNo from tab a,(select termid,max(batchNo) as batchNo from tab where termid in('000001','000002','000003') group by termid) b where a.termid=b.termid and a.batchNo=b.batchNo
------解决方案-------------------- mysql测试没问题 select TermId,max(BatchNo),BalanceNo from term where TermId in (1,2,3) group by TermId
------解决方案-------------------- 这个情况我在项目中遇到过
SQL code
Select Termid,BatchNo,BalanceNo from tab a where BatchNo=(Select Max(BatchNo) from tab where Termid=a.Termid group by Termid)