我有一个包含许多应用程序和日期的表。 我需要选择申请数量最多且一个月的一年。 我的表看起来像:
CisloSmlouvy | DatumZadosti
121651566 | 3-1-2010 07:23:21
121651516 | 7-5-2011 08:23:21
121551567 | 1-9-2010 09:25:21
121651562 | 3-5-2017 17:23:21
我想:
Best year | NumberOfApplications
2016 | 21565
Best month| NumberOfApplications
May | 215
我试过
;WITH resultset AS(
SELECT
COUNT(CisloSmlouvy) AS PocetSmluv
,DATEPART(YYYY, CAST(DatumZadosti AS DATE)) AS [Year]
,RN = RANK()OVER(PARTITION BY DATEPART(YYYY, CAST(DatumZadosti AS DATE)) ORDER BY DATEPART(YYYY, CAST(DatumZadosti AS DATE)))
FROM dbo.Smlouvy
GROUP BY
DATEPART(YYYY, CAST(DatumZadosti AS DATE))
,RANK()OVER(PARTITION BY DATEPART(YYYY, CAST(DatumZadosti AS DATE)) ORDER BY DATEPART(YYYY, CAST(DatumZadosti AS DATE)))
)
SELECT * FROM resultset WHERE RN = 1
任何帮助都会受到重视。感谢。
答案 0 :(得分:1)
窗口功能可以帮助您:
SELECT TOP(1)
YearCount = COUNT(CisloSmlouvy) OVER (PARTITION BY DATEPART(YEAR, CAST(DatumZadosti AS DATE)))
,MonthCount = COUNT(CisloSmlouvy) OVER (PARTITION BY DATEPART(YEAR, CAST(DatumZadosti AS DATE)), DATEPART(MONTH, CAST(DatumZadosti AS DATE)))
,[Year] = DATEPART(YEAR, CAST(DatumZadosti AS DATE))
,[Month] = DATEPART(MONTH, CAST(DatumZadosti AS DATE))
FROM dbo.Smlouvy
ORDER BY YearCount DESC, MonthCount DESC
答案 1 :(得分:0)
这并不容易,因为可能存在联系。我建议分别选择最佳年份和最佳月份,并使用final HtmlPage page1 = webClient.getPage("https://jira/secure/Dashboard.jspa");
final HtmlForm form = page1.getFormByName("loginform");
final HtmlTextInput textField = form.getInputByName("os_username");
final HtmlPasswordInput pwd = form.getInputByName("os_password");
textField.setValueAttribute(jname);
pwd.setValueAttribute(jpasswd);
final HtmlPage page2 = (HtmlPage) form.getInputByValue("Login").click();
结合两个结果:
UNION ALL