目前正在处理该报告。我需要的是 样本表,
Instance Type Sep-23 Sep-16 Sep-09 Sep-02 Aug-26 Aug-19
-------------------------------------------------------------------------
Early ASN 4 2 4 1 1 2
Late ASN 2 1 5 3 1 1
Sum 6 3 9 4 2 3
但实际表是,
SPGI01_INSTANCE_TYPE_C SPGI01_CREATE_S
--------------------------------------------------------------
Early ASN 9/17/2012 12:00:00.000
Early ASN 9/18/2012 10:06:11.000
Early ASN 9/19/2012 8:00:04.000
Early ASN 9/20/2012 3:00:05.000
Early ASN 9/10/2012 12:00:07.000
Early ASN 9/11/2012 12:00:32.000
Early ASN 9/3/2012 12:00:17.000
Early ASN 9/4/2012 10:06:00.000
Early ASN 9/5/2012 8:00:00.000
Early ASN 9/6/2012 3:00:00.000
Early ASN 8/31/2012 12:00:00.000
Early ASN 8/26/2012 12:00:00.000
Early ASN 8/14/2012 12:00:00.000
Early ASN 8/15/2012 12:00:00.000
Late ASN 9/17/2012 12:00:00.000
Late ASN 9/18/2012 10:06:00.000
Late ASN 9/11/2012 12:00:00.000
Late ASN 9/3/2012 12:00:00.000
Late ASN 9/4/2012 10:06:00.000
Late ASN 9/5/2012 8:00:00.000
Late ASN 9/6/2012 3:00:00.000
Late ASN 9/6/2012 2:00:00.000
Late ASN 8/31/2012 12:00:00.000
Late ASN 8/31/2012 12:00:00.000
Late ASN 8/31/2012 12:00:00.000
Early ASN 8/15/2012 12:00:00.000
我需要按照“SPGI01_INSTANCE_TYPE_C”列进行分组,并将每周星期日分组到最后六周的星期日。在这里我粘贴了两个样本表,一张表是我想要的,另一张表就是我所拥有的。给我解决方案。
我的查询是,
SELECT distinct I01.[SPGI01_INSTANCE_TYPE_C],
count (I01.[SPGI01_INSTANCE_TYPE_C])
FROM [SUPER-G].[dbo].[CSPGI01_ASN_ACCURACY] I01,
[SUPER-G].[dbo].[CSPGI50_VALID_INSTANCE_TYPE] I50
where
I01.[SPGA02_BUSINESS_TYPE_C] = 'prod'
and
I01.[SPGA03_REGION_C] in( 'ap','na','sa','eu')
and
I01.[SPGI01_SUB_BUSINESS_TYPE_C] = 'PRD'
and
(I01.[SPGI01_CREATE_S] between '2012-01-01 12:00:00.000' AND DATEADD(day , 7, '2012-01-15 00:00:00.000'))
and
I01.[SPGI01_EXCEPTIONED_F] = 'N'
and
I01.[SPGI01_DISPUTED_F] != 'Y'
and
I50.[SPGI50_INSTANCE_TYPE_C] = I01.[SPGI01_INSTANCE_TYPE_C]
and
I50.[SPGA04_RATING_ELEMENT_D] = 1
group by I01.[SPGI01_INSTANCE_TYPE_C]
答案 0 :(得分:1)
我对您发布的数据做了一些假设。
首先,您发布的值均为2011
,但最终结束日期为列标题与2011
不对应,它们是Sunday
的{{1}}值所以我改变了数据。同样,2012
的最终条目,我相信应该是Early ASN 8/15/2011 12:00
条目,否则要完成的总数匹配。
要获得结果,您希望自己想要应用PIVOT
功能。此功能允许您聚合值,然后将它们转换为列。
Late ASN