test sql

0

Please login or register to vote for this query.

(click on this box to dismiss)

Anime and Manga

Q&A for anime and manga fans

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
t5.id
,t6.boss_id
from
@table t5
left join 
@table t6
on t5.boss_id=t6.id
and t6.salary>=t5.salary*2
where
t6.salary is not null

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results