Drew L. Facchiano Drew L. Facchiano - 2 months ago 9
SQL Question

Add a new column with the diff of two values

SQL is goofy sometimes ain't it? Right now I want to take two values from different column and compare the difference. Ex:

ColA | ColB | New column
1 | 0 | 1
2 | 5 | 3
3 | 10 | 7


What should I do i order to create this RAD new column?

Answer Source

You could use computed/calculated column:

ALTER TABLE tab_name
ADD new_column AS (ABS(ColB - ColA));

DBFiddle Demo