我在那裏的數據將顯示這樣一個表中的數據:如何列轉換爲行
DatePeriod Good Fair Poor NotCategorised NotTested GoodPercentage FairPercentage PoorPercentage NotCategorisedPercentage NotTestedPercentage
Feb-13 4 0 0 0 60 6.25 0 0 0 93.75
而對於這一次我已經使用UNPIVOT書面查詢。
Select DatePeriod,Legend FROM
(
select DatePeriod,Good,Fair,Poor,NotCategorised,NotTested,GoodPercentage,
FairPercentage,poorPercentage,NotCategorisedPercentage,NotTestedPercentage from #cte
)P
UNPIVOT(Legend FOR #CTE IN (Good,Fair,Poor,NotCategorised,NotTested))AS UNPVT;
我沒有得到所需要的輸出
我的結果集必須這樣的:
year Legend percent count
Dec-12 Good 13.89 35
Dec-12 Fair 0 0
Dec-12 Poor 0 0
Dec-12 NC 0 0
Dec-12 NoData 86.11 217
我建議最好的方式。
它有助於提供表定義,和你實際看到的結果。我們輸入的越少,爲了測試更快,您將得到答案。 – BlackICE