如何仅选择表格中的最新条目?

编程入门 行业动态 更新时间:2024-10-24 04:50:14
本文介绍了如何仅选择表格中的最新条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 3 表的 SQLServer 数据库.

I have a 3 table SQLServer Database.

Project ProjectID ProjectName Thing ThingID ThingName ProjectThingLink ProjectID ThingID CreatedDate

当一个事物被归于一个项目时,一个条目会被放入 ProjectThingLink 表中.事情可以在项目之间移动.CreatedDate 也用于知道上次移动的是哪个项目.

When a Thing is ascribed to a Project an entry is put in the ProjectThingLink table. Things can move between Projects. The CreatedDate is used to know which Project a Thing was last moved too.

我正在尝试创建一个列表,列出当前与事物相关联的所有项目,但我的大脑出现故障.

I am trying to create a list of all Projects with which Things are currently linked to them, but my brain is failing.

有没有简单的方法可以做到这一点?

Is there an easy way of doing this?

推荐答案

select p.projectName, t.ThingName from projects p join projectThingLink l on l.projectId = p.projectId join thing t on t.thingId = l.thingId where l.createdDate = ( select max(l2.createdDate) from projectThingLink l2 where l2.thingId = l.thingId );

注意:评论后更正

更多推荐

如何仅选择表格中的最新条目?

本文发布于:2023-10-14 21:53:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492320.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条目   表格   最新

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!