Lucky Makhado Lucky Makhado - 1 year ago 72
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

Answer Source

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; 


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download