Insert excerpt | ||||||||
---|---|---|---|---|---|---|---|---|
|
Multi-Hop Worked Examples
This example uses the School In this example, we will explore how data can be accessed across different tables even where the tables do not have a direct relationship. This is called multi-hop and PhixFlow supports multi-hop relationships to a distance of 4 hops. In the below examples we will use the School Data from the Learning Centre, containing tables for Students, Attendees, Courses, Teachers, Departments and Classrooms.
ERD Setup
Accessing Attributes
- On a View on the Courses table, you can access the Department name and Student name
Aggregating on Attributes
HTML Comment | ||
---|---|---|
| ||
|
Example 1: Show Course Details
We want to see the details for each course, including its classroom, students and teacher. This involves 2 hops between the Courses and Students tables.
- On the ERD, click on the Courses table header to open the table configuration
- In the Properties, in the Views section, create a new view
- Name:
CourseDetails
- Save the View
- Name:
- In the View Attributes section, click the
iconInsert excerpt _attributes_icon _attributes_icon nopanel true - In the Available Attributes window:
- From the Courses table, drag across the CourseID and Name attributes into the View Attributes section of the View
- Under Related Tables, select the Classrooms table
- Drag across the ClassroomID and Name attributes into the View Attributes section of the View
- Under Related Tables, click back onto the Courses table, then onto the Attendees table (this allows us to hop to the Attendee's related tables), then onto the Students table
- Drag across the StudentID and Name attribute into the View Attributes section of the View
- Click back onto the Courses table using the link above the attribute selector
- Then click onto the Teachers table under Related Tables
- Drag across the TeacherID and Name attribute into the View Attributes section of the View
- Drag across the TeacherID and Name attribute into the View Attributes section of the View
- Optionally, set a Default Sort Order on the view
- Display the data in the View by hovering over
and clickingInsert excerpt _more_options _more_options nopanel true
DisplayInsert excerpt _view_show_icononly _view_show_icononly nopanel true
Example 2: Show Courses Attended By Female Students
We want to see all courses attended by female students. This involves 2 hops between the Courses and Students tables.
- On the ERD, click on the Courses table header to open the table configuration
- In the Properties, in the Views section, create a new view
- Name:
StudentsOnCourses
- Save the View
- Name:
- In the View Attributes section, click the
iconInsert excerpt _attributes_icon _attributes_icon nopanel true - In the Available Attributes window:
- From the Courses table, drag across the CourseID and Name attributes into the View Attributes section of the View
- Under Related Tables, select the Attendees table - this allows us to hop to the Attendee's related tables
- Drag across the StudentID attribute into the View Attributes section of the View
- Under Related Tables, select the Students table
- Drag across the Name and Gender attribute into the View Attributes section of the View
- Drag across the Name and Gender attribute into the View Attributes section of the View
- In the Data Retrieval Options on the View, create a new Default Filter
- Filter: create a new filter
- Name:
FemalesOnly
- Filter Details:
Gender
equalsFemale
- Name:
- Filter: create a new filter
- Optionally, set a Default Sort Order on the view
- Display the data in the View by hovering over
and clickingInsert excerpt _more_options _more_options nopanel true
DisplayInsert excerpt _view_show_icononly _view_show_icononly nopanel true
Example 3: Quantity of Males vs Females on Each Course
This example uses aggregation. We want to see the number of males and females on male and female students taking each course. This involves 2 hops between the Courses and Students data.
- On the ERD, click on the Course table header to open the table configuration
- In the Properties, in the Views section, create a new Viewview
- Name:
CourseByGender
- Save the View
- Name:
- In the View Attributes section, click the
iconInsert excerpt _attributes_icon _attributes_icon nopanel true - In the Available Attributes window:
- From the Course table, drag across the CourseID and Name attributes into the View Attributes section of the View
- Under Related Tables, select the Attendees table - this allows access us to hop to the Attendee's related tables
- Under Related Tables, select the Students table
- Drag across the Gender attribute twice into the View Attributes section of the View
- Double click on one of the Schools_StudentsGender attributes
- On the View Attributes properties:
- Name:
Males
- Aggregate Function: choose
Count
- Filter: create a new filter
- Name:
ByMales
- Filter Details:
Gender
contains equalsMale
- Name:
- Name:
- On the View Attributes properties:
- Repeat these steps for the other Schools_StudentsGender attribute but this time for Females
- Optionally, set a Default Sort Order on the view
- Display the data in the View by hovering over
and clickingInsert excerpt _more_options _more_options nopanel true
DisplayInsert excerpt _view_show_icononly _view_show_icononly nopanel true
Example 2: Students on Each Course
Example 4: Quantity of Courses in Each Department
This example uses aggregation. We want to see how many courses are in each department.
- On the ERD, click on the Department table header to open the table configuration
- In the Properties, in the Views section, create a new view
- Name:
CoursesCount
- Save the View
- Name:
- In the View Attributes section, click the
iconInsert excerpt _attributes_icon _attributes_icon nopanel true - In the Available Attributes window:
- From the Department table, drag across the Name attribute into the View Attributes section of the View
- To access the Courses table, under Related Tables, select either the Teachers table or Classrooms table
- Under Related Tables, select the Courses table
- Drag across the CourseID attribute into the View Attributes section of the View
- Double click on the CourseID attribute
- On the View Attributes properties:
- Name:
CourseCount
- Aggregate Function: choose
Count
- Name:
- On the View Attributes properties:
- Optionally, set a Default Sort Order on the view
- Display the data in the View by hovering over
and clickingInsert excerpt _more_options _more_options nopanel true
DisplayInsert excerpt _view_show_icononly _view_show_icononly nopanel true
HTML Comment | ||
---|---|---|
| ||
Example IdeasCourses with the most students? How many males do maths level 1 how many students are on a course see all males and females on maths level 1 since 2021 Students on Each Course: We want to see the number of males and females on each course. Example 2:Students and Teachers in a Department We : We want to see the names of teachers and students umber of on each course.
|