2
我提供了以下數據集:SQL在表的末尾添加行和列,以顯示平均
ID STATION ID DATE ELEMENT ID 00 01 02 03......23
1 6106000 2009-05-11 110 2550 900 1050 1550 3000
2 6106000 2009-05-12 110 380 1400 1550 5090 200
3 6106000 2009-05-13 110 500 1250 800 3550 4020
從數據集,我已經計算概率過去幾年的某些天。這是我在SQL已經寫道:
SELECT * FROM
(SELECT
DatePart(year, date) AS 'Date',
Format([DATE],'MMM dd') AS 'Day',
Probability = Cast(Round(((
IIf([00]>1410,1,IIf([00]=0,1,0)) +
IIf([01]>1410,1,IIf([01]=0,1,0)) +
IIf([02]>1410,1,IIf([02]=0,1,0)) +
IIf([03]>1410,1,IIf([03]=0,1,0)) +
IIf([04]>1410,1,IIf([04]=0,1,0)) +
IIf([05]>1410,1,IIf([05]=0,1,0)) +
IIf([06]>1410,1,IIf([06]=0,1,0)) +
IIf([07]>1410,1,IIf([07]=0,1,0)) +
IIf([08]>1410,1,IIf([08]=0,1,0)) +
IIf([09]>1410,1,IIf([09]=0,1,0)) +
IIf([10]>1410,1,IIf([10]=0,1,0)) +
IIf([11]>1410,1,IIf([11]=0,1,0)) +
IIf([12]>1410,1,IIf([12]=0,1,0)) +
IIf([13]>1410,1,IIf([13]=0,1,0)) +
IIf([14]>1410,1,IIf([14]=0,1,0)) +
IIf([15]>1410,1,IIf([15]=0,1,0)) +
IIf([16]>1410,1,IIf([16]=0,1,0)) +
IIf([17]>1410,1,IIf([17]=0,1,0)) +
IIf([18]>1410,1,IIf([18]=0,1,0)) +
IIf([19]>1410,1,IIf([19]=0,1,0)) +
IIf([20]>1410,1,IIf([20]=0,1,0)) +
IIf([21]>1410,1,IIf([21]=0,1,0)) +
IIf([22]>1410,1,IIf([22]=0,1,0)) +
IIf([23]>1410,1,IIf([23]=0,1,0)))/24.0)*100.0,0) AS int)
FROM
ON_2
WHERE
((([ELEMENT ID])=110) AND
(([STATION ID])='6106000') AND
((Day([DATE])) BETWEEN 1 AND 15) AND
((DatePart("m",[DATE]))=12))) AS BaseData
PIVOT
(MAX([Probability])
FOR [DATE]
IN ([2000],[2001],[2002],[2003],[2004],[2005],[2006],[2007],[2008],[2009],[2010],[2011])) AS PivotTable
運行查詢後,結果如下:
Day 2000 2001 2002 2003....2011
Dec 01 100 19 20 68......95
Dec 02 56 33 80 77......35
Dec 03 90 52 39 10......45
.
.
Dec 15 58 43 70 25......99
我在這裏的問題是,我不能夠增加一列和行顯示平均值。這是我試圖得到的最終結果:
Day 2000 2001 2002 2003....2011 Avg
Dec 01 100 19 20 68......95 60
Dec 02 56 33 80 77......35 88
Dec 03 90 52 39 10......45 48
.
.
Dec 15 58 43 70 25......99 55
Avg 75 40 55 33......58
感謝您的時間和事先幫助。
我感謝您的幫助,但我不能夠獲得有意義的結果與 – 2015-01-15 16:52:35
@OscarDuran - 更新檢查現在 – 2015-01-15 17:11:46
非常感謝你,完美地工作! :) – 2015-01-15 17:27:15