获取内容组 SQL 的最新版本
我有内容表,其中有许多内容和这些内容的各种版本。 这些列是 content varchar
、document_id int
(标识多个版本之间的内容)和 version int
我想返回每个内容组的最新版本。我尝试使用此 SQL,但它只返回第一个版本,但我想要最后一个版本。 order by 不适用于 group by。
SELECT * FROM content where id_project = 8 group by document_id order by version desc;
如何获取所有唯一内容的最新版本(唯一内容由 document_id 标识)?
谢谢如果有人可以帮助我
I have content table where I have many contents and various versions of those contents.
The columns are content varchar
,document_id int
(identifies a content between many versions) and version int
I want to return the lastest version of each content group. I tried using this SQL but it returns me just the first version but I want the last.The order by doesn't work with group by.
SELECT * FROM content where id_project = 8 group by document_id order by version desc;
How can i get the lastest version of all unique content(unique content is identified by the document_id)?
Thanks if anyone can help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从内容中选择 document_id,MAX(version) WHERE id_project = 8 GROUP BY document_id
SELECT document_id,MAX(version) FROM content WHERE id_project = 8 GROUP BY document_id
我相信您想要类似
假设每组版本均按
document_id
“分组”的内容。I believe you want something like
Assuming each set of versions is "grouped" by a
document_id
.