c# - SQL query using sum(column) in pivot function -
from sql query count item report per day of month?
i can report code:
select name, [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24], [25], [26], [27], [28], [29], [30], [31], ([1] + [2] + [3] + [4] + [5] + [6] + [7] + [8] + [9] + [10] + [11] + [12] + [13] + [14] + [15] + [16] + [17] + [18] + [19] + [20] + [21] + [22] + [23] + [24] + [25] + [26] + [27] + [28] + [29] + [30] + [31]) total ( select name, id, datepart(day, [date]) day item month([date]) = 2 , year([date]) = 2015 ) x pivot ( count(id) day in ([1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24], [25], [26], [27], [28], [29], [30], [31]) ) p
but now, have new column (amount
) in table (see http://imagizer.imageshack.us/a/img911/110/hcx7ho.png)
and need sum(amount)
replace count(id)
total amount day.
i try add select column amount
, sum(amount)
replace count(id)
, not working (i got it:http://imageshack.com/a/img911/6023/zhme7i.png)
please me or guide me.
do need both, count(id) , sum(amount) ? if yes need 2 pivot queries. otherwise should able replace id amount this:
..... ( select name, amount, datepart(day, [date]) day item month([date]) = 2 , year([date]) = 2015 ) x pivot ( sum(amount) day in ([1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24], [25], [26], [27], [28], [29], [30], [31]) ) p