user1561790 user1561790 - 3 years ago 72
SQL Question

columns from another table an arithmetic operations using SQL

I am learning to use SQL. I have two tables Table1 and Table2. I need to fetch three columns from Table1 say A,B,C and add them as A,B and C on table2. also perform arithmetic operation on Column D and E using Column C on table2.
I tried
insert into Table2(A,B,C)
select(A,B,C ) from Table1.
Now how do I do the arithmetic calculation on column D and E on table 2. It goes like this C*5 as D
and c*10 as E
Any help here Is highly appreciated

Answer Source

I assume this is what you want:

insert into Table2 (A,B,C,D,E)
select A,B,C,5*C,10*C from Table1

You might consider using a view instead of a table:

create view V2 as (
    select A, B, C, 5*C as D, 10*C as E 
    from Table1

Unless you are using D and E in predicates, there should not be much performance penalty.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download