筛选出某个用户的各个baby的最新记录
select a.Id,a.UserId,a.BabyId,a.BabyName,a.CreateTime from [Hmeshop_BabyInfo] as a inner join(select UserId,BabyId,MAX(CreateTime) CreateTime from [Hmeshop_BabyInfo] where UserId=26912
group by userId,BabyId) as b on a.UserId=b.UserId and a.CreateTime=b.CreateTime and a.BabyId=b.BabyId where a.UserId=26912
查询结果如下:

本文介绍了一种SQL查询方法,用于筛选特定用户所有Baby的最新记录,通过内连接子查询实现,确保了每个Baby的记录是最新的。
3177

被折叠的 条评论
为什么被折叠?



