view raw
Lucky Makhado Lucky Makhado - 9 months ago 37
SQL Question

I want to find difference between two presenters salary

I have the following table

Presenters(pre_name, salary)

Suppose I have the following values

Values ( 'A', 8 )
( 'B', 6 )
( 'C', 7 )

I want the following results

Pre-name pre-name salary-diff
A B 2
A C 1
B C -1


Looks like you need something like

SELECT p1.pre_name,
       p1.salary - p2.salary AS "salary-deff"
FROM   Presenters p1
       JOIN Presenters p2
         ON p2.pre_name > p1.pre_name;