income during month in sql server 2008 -



income during month in sql server 2008 -

i have table called visiting, have 2 column (visiting date) , ( cost ) that

visiting_date cost 20-6-2014 50 20-6-2014 50 21-7-2014 200 21-7-2014 200

i want create view can sum cost of each month individual output

month income 6 100 7 400

thank helping

you need utilize group by , datepart

the op asked summed month specifically. want add together order create list more comprehensible. also, without simplicity defining ascending or descending dbms assume ascending.

select sum(cost) income, datepart(month, visiting_date) month table1 grouping datepart(month, visiting_date) order datepart(month, visiting_date)

if 1 wanted split out (year,month) or utilize illustration below. in chose order year , month:

select sum(cost) income, datepart(month, visiting_date) month, datepart(year, visiting_date) year table1 grouping datepart(year, visiting_date), datepart(month, visiting_date) order datepart(year, visiting_date), datepart(month, visiting_date)

sql sql-server database sql-server-2008

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -