我有一个问题:
SELECT
CONVERT(varchar(7),SUBMITDATE, 120) as 'Month'
,CASE WHEN ReportType = '1' THEN (SELECT AVG(DATEDIFF(DAY,SUBMITDATE,DateClosed))) END as 'Report1Avg'
,CASE WHEN ReportType = '2' THEN (SELECT AVG(DATEDIFF(DAY,SUBMITDATE,DateClosed))) END as 'Report2Avg'
,CASE WHEN ReportType = '3' THEN (SELECT AVG(DATEDIFF(DAY,SUBMITDATE,DateClosed))) END as 'Report3Avg'
,CASE WHEN ReportType = '4' THEN (SELECT AVG(DATEDIFF(DAY,SUBMITDATE,DateClosed))) END as 'Report4Avg'
,CASE WHEN ReportType = '5' THEN (SELECT AVG(DATEDIFF(DAY,SUBMITDATE,DateClosed))) END as 'Report5Avg'
FROM Table1
WHERE STATUS = 'Closed'
GROUP BY CONVERT(varchar(7),SUBMITDATE, 120), ReportType
ORDER BY CONVERT(varchar(7),SUBMITDATE, 120)
产生以下结果:
我的问题是:如何将每个月的结果合并为一行? 恩。对于'2015-06',我有3行结果。
这可能吗?
答案 0 :(得分:1)
在import from StringIO import StringIO
import urllib
file_like_object = StringIO(urllib.urlopen(url).read())
表达式周围使用avg
。还可以使用case
来避免空值。
else 0