Reputation: 537
I have two columns in table and I am trying to calculate diff between least performer to every cell in the column.
Column_a column_B
abc 1
DEF 5
GHI 7
JKL 8
I am trying to get an output like below
abc 1 0
def 5 4
ghi 5 6
jkl 8 7
Column_c diff between each cell in column b to min(column b)
Upvotes: 0
Views: 37
Reputation: 1269813
Use window functions:
select column_a, column_b, (column_b - min(column_b) over ())
from t;
Upvotes: 0
Reputation: 16908
Try this.
SELECT Column_a , Column_b,
Column_b- (SELECT MIN(Column_b) FROM your_table) AS Column_c
FROM Your_table
Upvotes: 2