SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 adding based on same entity in the column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

goligol
Posting Yak Master

128 Posts

Posted - 02/15/2013 :  15:16:48  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3588 Posts

Posted - 02/15/2013 :  15:54:41  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 02/16/2013 :  02:28:41  Show Profile  Reply with Quote
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 - 02/18/2013 :  13:10:54  Show Profile  Reply with Quote
Thank you James and VisaKh.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 02/18/2013 :  13:31:53  Show Profile  Reply with Quote
welcome

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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.27 seconds. Powered By: Snitz Forums 2000