sql server - Re-arrange data in sql table using pivot -


i have data:

2014-10-28  excess   1025   98297654999.82 2014-10-29  excess   251    1902171582.07 2014-10-28  pastdue  1590   7645464003.17 2014-10-29  pastdue  13       3704776.10 

i need data this:

date       excesscount  excessamt   passcount   passamt 28/10/2015  1025       98297655000     1590     7645464003 29/10/2015  251        1902171582      13       3704776.1 

please let me know how this.

check out

select column1 date, sum(excesscount) excesscount, sum(excessamt) excessamt, sum(pastduecount) pastduecount, sum(pastdueamt) pastdueamt  (   select column1,column3,column4, column2+'count' tempcol1,column2+'amt' tempcol2   tablename ) x pivot (   min(column3)   tempcol1 in ([excesscount], [pastduecount]) ) p pivot (   min(column4)   tempcol2 in ([excessamt], [pastdueamt]) ) q group column1 

put main table column names @ column1, column2, column3, column4

fyi..

enter image description here


Comments