由于我不擅长 sql 和设计器无法使用 OVER ,因此为此苦苦挣扎。基本上,如果用户关注关联的标签,这将获取主题列表。
我需要分组T.TopicId
以停止重复。如果用户选择与某个主题相关的多个标签,它将列出该主题两次(每个标签一次)
当我在 sql 中添加 group by 时,出现多个错误,并且我尝试重新安排事物并且无法使其正常工作,正如所说的,我对 sql 语句没用
@id int = null
AS
SELECT
*
FROM
(SELECT
ROW_NUMBER()
OVER
(ORDER BY TopicOrder desc
,
(CASE
WHEN M.MessageCreationDate > T.TopicCreationDate THEN M.MessageCreationDate
ELSE T.TopicCreationDate
END) desc)
AS RowNumber
,T.TopicId, T.TopicTitle, T.TopicShortName, T.TopicDescription, T.TopicCreationDate, T.TopicViews, T.TopicReplies, T.UserId, T.TopicTags, T.TopicIsClose,
T.TopicOrder, T.LastMessageId, T.UserName, M.MessageCreationDate, M.UserId AS MessageUserId, MU.UserName AS MessageUserName, U.UserGroupId,
U.UserPhoto, T.UserFullName
FROM Tags INNER JOIN
TopicsComplete AS T ON T.TopicId = Tags.TopicId LEFT OUTER JOIN
Messages AS M ON M.TopicId = T.TopicId AND M.MessageId = T.LastMessageId AND M.Active = 1 LEFT OUTER JOIN
Users AS MU ON MU.UserId = M.UserId LEFT OUTER JOIN
Users AS U ON U.UserId = T.UserId LEFT OUTER JOIN
tagfollows AS TF ON @id = TF.userid
WHERE (Tags.Tag = TF.tag)
)T
如果有人可以提供帮助,将不胜感激,谢谢!:)