[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

Looping through a table and adding a column

I need some assistance with the sql to accomplish the desired outcome.  
Here is an example of what the data could look like in the table.
Table X
   L_ID                        C_ID          Indem
 32566                      54345        25.00
 32566                      54346       26.00
 32566                      54346        37.00
 32566                      54347         45.00

I will be writing this data to another table.  What I will be doing is taking everthing from the specified table X with the same L_ID and inserting it into another table.  The one thing that will change is that I need to add the Indem column when the C_ID is equal to another C_ID.  So with that said the C_ID with 54346  will need to have their Indem values added together and inserted into table Y.  
0
oak29
Asked:
oak29
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
insert into to_table select l_ID, C_ID, sum(indem) from  from_table group by l_id, c_id
0
 
oak29Author Commented:
Thanks!  Wow, that was a lot easier than I made it out to be.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now