Run Code  | API  | Code Wall  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

Row wise arithmetic operation using pivot and unpivt

Language: Layout:
View schema
Execution time: 0.05 sec, rows selected: 30, rows affected: 7, absolute service time: 0.2 sec 
fork mode |  history  | discussion
   EmpId Yr price
1 1 2005 12000.0000
2 1 2006 18000.0000
3 1 2007 25000.0000
4 2 2005 15000.0000
5 2 2006 6000.0000
6 3 2006 20000.0000
7 3 2007 24000.0000
   EmpId Yr totalsales total Grand Total
1 1 2005 12000.0000 55000.0000 120000.0000
2 1 2006 18000.0000 55000.0000 120000.0000
3 1 2007 25000.0000 55000.0000 120000.0000
4 2 2005 15000.0000 21000.0000 120000.0000
5 2 2006 6000.0000 21000.0000 120000.0000
6 3 2006 20000.0000 44000.0000 120000.0000
7 3 2007 24000.0000 44000.0000 120000.0000
   (No column name)
1 [2005],[2006],[2007]
   EmpId total 2005 2006 2007
1 1 55000.0000 12000.0000 18000.0000 25000.0000
2 2 21000.0000 15000.0000 6000.0000 NULL
3 3 44000.0000 NULL 20000.0000 24000.0000