test sql

0

Please login or register to vote for this query.

(click on this box to dismiss)

Russian Language

Q&A for students, teachers, and linguists wanting to discuss the finer points of the Russian language

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

Enter Parameters

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