Is the following query possible with SQL Pivot?

后端 未结 2 1176
情深已故
情深已故 2021-01-12 11:49

Let\'s say I have the following tables:

create table student(
  id number not null,
  name varchar2(80),
  primary key(id)
);

create table class(
  id numbe         


        
2条回答
  •  感情败类
    2021-01-12 11:57

    Disclaimer: I don't know apex specifically.

    Here's a correct pivot query, assuming the class you want has an ID = 1, and that the meeting_id's for that class are 1,2,3.

    select * from(
      select s.name, a.present,m.id meeting_id
      from student s, meeting_attendance a, class_meeting m, class c
      where s.id = a.student_id
        and m.id = a.meeting_id
        and c.id = m.class_id 
        and c.id = 1
    )
    pivot(
          sum(present)
          for meeting_id in(1,2,3)
    );
    

    I don't believe you can use a sub-query to return the values for the "for in" of the pivot.

提交回复
热议问题