嗨,大家好,你可以帮我创建这个内部联合查询。
这个想法是我需要首先得到哪个是前3个最高关键字计数然后显示每月关键字数量(我只需要月份数)
SELECT ReportRaw.Keyword, Format([DateApplying],'m') AS appdate, Count(ReportRaw.Keyword) AS CountOfKeyword1
FROM
(
SELECT TOP 3 Count(Keyword) AS CountOfKeyword,Keyword
FROM ReportRaw
GROUP BY Keyword
ORDER BY Count(Keyword) DESC;
) as T1
INNER JOIN ReportRaw
ON T1.Keyword = ReportRaw.Keyword
GROUP BY ReportRaw.Keyword, Format([DateApplying],'m') ;
答案 0 :(得分:0)
看起来像DESC之后的分号(;)。假设这是SQL Server
对查询进行微小更新以获取该月份数字:
SELECT #ReportRaw.Keyword, DATEPART(MONTH, [DateApplying]) AS appdate,
Count(#ReportRaw.Keyword) AS CountOfKeyword1
FROM
(
SELECT TOP 3 Count(Keyword) AS CountOfKeyword,Keyword
FROM #ReportRaw
GROUP BY Keyword
ORDER BY Count(Keyword) DESC
) as T1
INNER JOIN #ReportRaw
ON T1.Keyword = #ReportRaw.Keyword
GROUP BY #ReportRaw.Keyword, DATEPART(MONTH, [DateApplying]) ;