test sql

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

declare @table table
(id int, 
name varchar(10), 
salary int, 
boss_id int)

insert @table values(1, 'James', 10000, null)
insert @table values(2, 'Alex',   5000, 1)
insert @table values(3, 'Alice',  1500, 4)
insert @table values(4, 'John',   3000, 2)
insert @table values(5, 'Omar',   2200, 4);


select
t1.*
,t2.boss_id

from
@table t1
left join 
@table t2
on t1.boss_id=t2.id
and t2.salary>=t1.salary*2

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results