Home > database >  How to sum values from a column that is null?
How to sum values from a column that is null?

Time:09-27

I need to do an union between 2 tables and there is a column on the first table that doesn't exist on the second table, so, I would like to set up a column with null's (e.g: select null as column_name from table2). However, it involves a SUM and I can't use "null as Sum(column_name)" since it doesn't work. Since the values are null, the sum would be 0. So, how do I select a sum from a column that doesn't exist in a table but I will insert null values on that column?

CodePudding user response:

In your union, when you select from the table that does not have the column in question, just include null as <column name> in the appropriate position in your select statement. Or you could do 0 as <column name>, whatever works better for you.

CodePudding user response:

You could apply ZEROIFNULL around that column to make them 0.

SUM(ZEROIFNULL(UnionColumn)) This should work fine with Teradata.

  • Related