Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 adding based on same entity in the column

Author  Topic 

goligol
Posting Yak Master

128 Posts

Posted - 2013-02-15 : 15:16:48
Hi
I would like to combine the all_qty_1_yr when the FIPS is the same:
like for the first two rows, I would like to sum the 19800 + 17994 because the FIPS is the same for this two values 01097
in new view I would like to keep:

FIPS all_qty_1yr columns only by having the summation on same FIPS


naics FIPS ust_code all_qty_1_yr all_qty_2_yr
11133912 01097 4840 19800 0
11133905 01097 4840 17994 0
11133913 04003 2010 375712.036007496 0
11133902 04003 2010 2017876.49509041 0
11133914 04013 2010 103561.978092157 0
11133505 04013 1220 9048 0
11133505 04023 2010 7502362 0
11132006 04023 2010 24114931.0388845 0
11133202 04023 2010 2636366 980733676
11133408 04023 2010 4595.98865871247 0

Thank you

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-02-15 : 15:54:41
Didn't quite follow what you meant by "columns only by having the summation on same FIPS". Also, did you want the other columns to show up in the output - if so how should they be aggreated? If this query does not give you what you want, can you post the desired output?
SELECT
FIPS,
SUM(all_qty_yr) AS Total_all_qty_yr
FROM
Tbl
GROUP BY
FIPS;
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-16 : 02:28:41
Based on your explanation it would either of James suggestion or this

SELECT *,SUM(all_qty_1_yr) OVER (PARTITION BY FIPS) AS CummSum
FROM table


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

goligol
Posting Yak Master

128 Posts

Posted - 2013-02-18 : 13:10:54
Thank you James and VisaKh.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-18 : 13:31:53
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -