Home > Mobile >  How do I sum the values of two columns?
How do I sum the values of two columns?

Time:12-08

here are two tables:

|column1|column2|
|------ |----   |
| A     |B      | 
|A1     |    B1 |
|A2     |B2     |

and

|column1a|column2a|
|------- |----    |
| A      |C       |
|A1      |C1      |
|A2      |C2      |

From this i want a table like that:

|newColumn|newColumn2|
|------- |----       | 
| A      | B   C     |
|A1      |B1   C1    |
|A2      |B2   C2|

Hope you can help me ;)

CodePudding user response:

In that simple case (is it really that simple? No additional rows in any of those tables?), then

SQL> select * from table1;

         A
----------
        10

SQL> select * from table2;

         B
----------
         2

SQL> create table table3 as
  2    select t1.a   t2.b as c
  3    from table1 t1 cross join table2 t2;

Table created.

SQL> select * from table3;

         C
----------
        12

SQL>

CodePudding user response:

Cast your Column Value to NUMBER

SELECT CAST(table1.A AS NUMBER) CAST(tableb.B AS NUMBER) as Sum
From table1 INNER JOIN tableb ON table1.Id=tableb.Id
  • Related