使用一个查询的结果来过滤下一个

时间:2018-05-23 15:24:06

标签: sql oracle oracle-apex

我有3个表UserInfo,Class& ClassAttendance。

我正在尝试合并两个查询,以便我可以更新我的用户信息

我的第一个查询在课程表中搜索日期范围内的课程

Select ClassID from Class 
Where ClassDate > '04/23/2018'

我的第二个查询根据成员参加课程的次数更新信息

update UserInfo 
SET ParticipationStatus = 'standard participant'
where (
select count(MemberID)
from ClassAttendance
WHERE UserInfo.MemberID=ClassAttendance.MemberID

) >= 4

我假设使用加入是最好的方法,但我无法弄清楚

1 个答案:

答案 0 :(得分:0)

您可以尝试pl / sql:

begin

for x in (select ClassID from Class 
                 where ClassDate > '04/23/2018')
loop
   for y in (select MemberID, count(ClassId) as Member_count from ClassAttendance
                    where ClassId = x.Class group by MemberId having count(ClassId) >=4 )
   loop
        update UserInfo SET ParticipationStatus = 'standard participant' where MemberID = y.MemberId;
   end loop;
end loop;

end;
相关问题