本文介绍了获取行取决于列数和最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 我有3个表:文件,用户和回复 文件表 docid docName sendTo 1 休假 1 2 private 1 用户表 userid userName 1 john 2 结婚 回复表 replyid docid userid replyDate 1 1 1 14-06 -2015 2 1 2 15-60-2015 如何创建查询获取最后回复日期的回复计数 当我选择的时候文件= 1(john)的se senderid如下所示: docName numOfReplies lastReply vacation 2 15-06-2015 private 0 null 我该怎么做才能得到这个结果? 编辑:AL)来自评论 这是我到目前为止所尝试的: SELECT distinct dbo.Documents.DocName, COUNT( *) over () AS [numOfReplies], max(dbo.Replies,replyDate) as [lastreply] FROM dbo.Documents INNER JOIN dbo.Replies ON dbo.Documents.DocumentID = dbo.Replies.DocumentID INNER JOIN dbo.Users ON dbo.Documents.SendTo = dbo.Users.UserID WHERE dbo.Users.UserID = 1 GROUP BY dbo.Documents.DocumentID 解决方案 i have 3 tables : Documents, Users and RepliesDocuments tabledocid docName sendTo1 vacation 12 private 1Users tableuserid userName1 john2 marryReplies tablereplyid docid userid replyDate1 1 1 14-06-20152 1 2 15-60-2015how can i create query get the count of replies with last reply datewhen i choose senderid of document=1 (john) appear like this :docName numOfReplies lastReplyvacation 2 15-06-2015private 0 nullhow can i do that to get this result?EDIT: AL) from commentsThis is what I have tried so far:SELECT distinct dbo.Documents.DocName, COUNT(*) over () AS [numOfReplies], max(dbo.Replies,replyDate) as [lastreply]FROM dbo.Documents INNER JOIN dbo.Replies ON dbo.Documents.DocumentID = dbo.Replies.DocumentID INNER JOIN dbo.Users ON dbo.Documents.SendTo = dbo.Users.UserIDWHERE dbo.Users.UserID = 1GROUP BY dbo.Documents.DocumentID 解决方案 这篇关于获取行取决于列数和最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-06 22:51