Hi Guys
I need a query for expected output below. Thanks in Advance
ID Name SUM QTY Val ROS 1 201305_10151_ROMA_ROMA 0 2 -2 1 2 201305_10151_ROMA_ROMA 0 2 -2 2 3 201305_10151_ROMA_ROMA 0 2 -2 3 4 201305_10151_ROMA_ROMA 2000 2 1998 4 5 201305_10151_ROMA_ROMA 2000 2 1998 5 6 201305_10151_ROMA_ROMA 4000 2 3998 6 7 201305_10151_ROMA_ROMA 4000 2 3998 7 8 201305_10151_ROMA_ROMA 6000 2 5998 8 9 201305_10151_ROMA_ROMA 6000 2 5998 9 10 201305_10151_ROMA_ROMA 8000 2 7998 10 11 201305_10151_ROMA_ROMA 10000 2 9998 11 12 201305_10151_ROMA_ROMA 12000 2 11998 12 9 201305_690_REKA_REKA 4329 4521 192 1 SUM<QTY 10 201305_690_REKA_REKA 4810 4521 289 2 8 201305_690_REKA_REKA 3848 4521 673 3 11 201305_690_REKA_REKA 5291 4521 770 4 7 201305_690_REKA_REKA 3367 4521 1154 5 12 201305_690_REKA_REKA 5772 4521 1251 6 6 201305_690_REKA_REKA 2886 4521 1635 7 5 201305_690_REKA_REKA 2405 4521 2116 8 4 201305_690_REKA_REKA 1924 4521 2597 9 3 201305_690_REKA_REKA 1443 4521 3078 10 2 201305_690_REKA_REKA 962 4521 3559 11 1 201305_690_REKA_REKA 481 4521 4040 12 2 201305_100_70_70 345 264 81 1 1 201305_100_70_70 159 264 105 2 SUM<QTY 3 201305_100_70_70 573 264 309 3 4 201305_100_70_70 751 264 487 4 5 201305_100_70_70 933 264 669 5 6 201305_100_70_70 1154 264 890 6 7 201305_100_70_70 1394 264 1130 7 8 201305_100_70_70 1607 264 1343 8 9 201305_100_70_70 1823 264 1559 9 10 201305_100_70_70 2047 264 1783 10 11 201305_100_70_70 2268 264 2004 11 12 201305_100_70_70 2502 264 2238 12 Expected Output 3 201305_10151_ROMA_ROMA 0 2 -2 3 9 201305_690_REKA_REKA 4329 4521 192 1 1 201305_100_70_70 159 264 105 2
Data Script
select 1 as ID, '201305_10151_ROMA_ROMA' as Name , 0 as Sum ,2 as Qty ,-2 as Val ,1 as Ros UNION ALL select 2, '201305_10151_ROMA_ROMA' ,0 ,2 ,-2 ,2 UNION ALL select 3, '201305_10151_ROMA_ROMA' ,0 ,2 ,-2 ,3 UNION ALL select 4, '201305_10151_ROMA_ROMA', 2000, 2, 1998, 4 UNION ALL select 5, '201305_10151_ROMA_ROMA' ,2000, 2, 1998, 5 UNION ALL select 6, '201305_10151_ROMA_ROMA' ,4000, 2, 3998, 6 UNION ALL select 7, '201305_10151_ROMA_ROMA' ,4000, 2, 3998, 7 UNION ALL select 8, '201305_10151_ROMA_ROMA' ,6000, 2, 5998, 8 UNION ALL select 9, '201305_10151_ROMA_ROMA' ,6000, 2, 5998, 9 UNION ALL select 10, '201305_10151_ROMA_ROMA' ,8000, 2, 7998, 10 UNION ALL select 11,'201305_10151_ROMA_ROMA' ,10000, 2 ,9998 ,11 UNION ALL select 12, ',201305_10151_ROMA_ROMA', 12000, 2, 11998, 12 UNION ALL select 9, '201305_690_REKA_REKA', 4329, 4521, 192 ,1 UNION ALL select 10, '201305_690_REKA_REKA', 4810, 4521, 289 ,2 UNION ALL select 8,'201305_690_REKA_REKA', 3848, 4521, 673 ,3 UNION ALL select 11, '201305_690_REKA_REKA', 5291, 4521, 770 ,4 UNION ALL select 7, '201305_690_REKA_REKA', 3367, 4521, 1154, 5 UNION ALL select 12, '201305_690_REKA_REKA', 5772, 4521, 1251, 6 UNION ALL select 6, '201305_690_REKA_REKA', 2886, 4521, 1635, 7 UNION ALL select 5, '201305_690_REKA_REKA', 2405, 4521, 2116, 8 UNION ALL select 4, '201305_690_REKA_REKA', 1924, 4521, 2597, 9 UNION ALL select 3, '201305_690_REKA_REKA', 1443, 4521, 3078, 10 UNION ALL select 2, '201305_690_REKA_REKA', 962, 4521, 3559, 11 UNION ALL select 1, '201305_690_REKA_REKA', 481, 4521, 4040, 12 UNION ALL select 2, '201305_100_70_70' ,345, 264 ,81, 1 UNION ALL select 1, '201305_100_70_70' ,159 ,264 ,105 ,2 UNION ALL select 3, '201305_100_70_70' ,573 ,264 ,309 ,3 UNION ALL select 4, '201305_100_70_70' ,751 ,264 ,487 ,4 UNION ALL select 5, '201305_100_70_70' ,933 ,264 ,669 ,5 UNION ALL select 6, '201305_100_70_70' ,1154, 264 ,890 ,6 UNION ALL select 7, '201305_100_70_70' ,1394, 264 ,1130 ,7 UNION ALL select 8, '201305_100_70_70' ,1607, 264 ,1343 ,8 UNION ALL select 9, '201305_100_70_70' ,1823, 264 ,1559 ,9 UNION ALL select 10, '201305_100_70_70' ,2047, 264 ,1783 ,10 UNION ALL select 11, '201305_100_70_70' ,2268, 264 ,2004 ,11 UNION ALL select 12, '201305_100_70_70' ,2502, 264 ,2238 ,12
Please help on it
/R.