我有一个查询如下问题在结果中我希望它按照特定周的TESTTool和Release版本进行分组。因此,如果我输入一系列日期,那么我应该根据发布版本和Testtool获取该周的testtool,Releaseversion,Week No,TotalNoscripts,Pass和fail百分比。但是如果我提供按日期分组的日期范围,那么我不想。
select TestTool,ReleaseVersion,WeekNo=DATEPART(wk,StartDate),YearNo=DATEPART(year,StartDate),
totalnoofscripts=count(ScriptName),PassPercentage=round(avg(case when Status='Pass' then 100.0 else 0.0 end), 2),
FailPercentage=round(avg(case when Status='Fail' then 100.0 else 0.0 end), 2)
from CitraTestLogging.dbo.TestScript as s1,CitraTestLogging.dbo.TestRun as s2
where s1.TestRun_ID=s2.ID and StartDate between '2017-12-01' and '2017-12-08'
group by TestTool,ReleaseVersion,StartDate order by TestTool,ReleaseVersion,StartDate;
答案 0 :(得分:0)
您只需要从组中删除startdate。
我在订单中添加了年份和星期,以便您获得订购的结果。 任何格式化你的SQL!
SELECT TestTool
,ReleaseVersion
,WeekNo = DATEPART(wk, StartDate)
,YearNo = DATEPART(year, StartDate)
,totalnoofscripts = count(ScriptName)
,PassPercentage = round(avg(CASE
WHEN STATUS = 'Pass'
THEN 100.0
ELSE 0.0
END), 2)
,FailPercentage = round(avg(CASE
WHEN STATUS = 'Fail'
THEN 100.0
ELSE 0.0
END), 2)
FROM CitraTestLogging.dbo.TestScript AS s1
,CitraTestLogging.dbo.TestRun AS s2
WHERE s1.TestRun_ID = s2.ID
AND StartDate BETWEEN '2017-12-01'
AND '2017-12-08'
GROUP BY TestTool
,ReleaseVersion
,DATEPART(year, StartDate)
,DATEPART(wk, StartDate)
ORDER BY TestTool
,ReleaseVersion
,DATEPART(year, StartDate)
,DATEPART(wk, StartDate);