select a.studentid , case when b.studentid is null then 0 else 1 end as value from student a left join (select distinct studentid from log) b on a.studentid = b.studentid
select a.studentid,case when (select 1 from log where studentid=a.studentid)=1 then 1 else 0 end as value from student as a
select studentid,(select case when count(1)=0 then 0 else 1 end from log where student.studentid=studentid) from student
select id,value=(select case when count(*)=0 then 0 else 1 end from log where stu.id=log.stuid) from stu
select * ,case when exists (select 1 from log where studentid = student.studentid) then 1 else 0 end from student
select * ,case when (select count(*) from log where studentid = student.studentid) > 0 then 1 else 0 end from student
select studentid,value=(select case when count(*)=0 then 0 else 1 end from log where student.studentid=studentid) from student
declare @student Table(studentid int) insert into @student values(1) insert into @student values(2) insert into @student values(3) insert into @student values(4) declare @log Table(id int,studentid int,bookname varchar(50)) insert into @log values(1,1,'book1') insert into @log values(2,2,'book2') insert into @log values(3,2,'book3') insert into @log values(4,2,'book3') insert into @log values(5,1,'book2') insert into @log values(6,2,'book2')select a.studentid, (case when a.studentid in (select b.studentid from @log b) then 1 else 0 End) as value from @student a
a.studentid ,
case when b.studentid is null then 0 else 1 end as value
from
student a
left join
(select distinct studentid from log) b
on
a.studentid = b.studentid
select a.studentid,case when (select 1 from log where studentid=a.studentid)=1 then 1 else 0 end as value from student as a
from stu
,case when exists (select 1 from log where studentid = student.studentid)
then 1
else
0
end
from student
,case when (select count(*) from log where studentid = student.studentid) > 0
then 1
else
0
end
from student
insert into @student values(1)
insert into @student values(2)
insert into @student values(3)
insert into @student values(4)
declare @log Table(id int,studentid int,bookname varchar(50))
insert into @log values(1,1,'book1')
insert into @log values(2,2,'book2')
insert into @log values(3,2,'book3')
insert into @log values(4,2,'book3')
insert into @log values(5,1,'book2')
insert into @log values(6,2,'book2')select a.studentid,
(case
when a.studentid in (select b.studentid from @log b) then 1
else 0
End) as value
from @student a